|
3 | 3 | // Import the module and reference it with the alias vscode in your code below |
4 | 4 | import * as Path from "path"; |
5 | 5 | import * as FS from "fs"; |
6 | | -import { window, workspace, ExtensionContext, commands, tasks, Task, TaskExecution, ShellExecution, Uri, TaskDefinition, languages, IndentAction, Progress, ProgressLocation } from 'vscode'; |
7 | | -import {LanguageClient, LanguageClientOptions, ServerOptions, NotificationType} from "vscode-languageclient"; |
| 6 | +import { window, workspace, ExtensionContext, commands, tasks, Task, TaskExecution, ShellExecution, Uri, TaskDefinition, languages, IndentAction, Progress, ProgressLocation, DecorationOptions, ThemeColor } from 'vscode'; |
| 7 | +import {LanguageClient, LanguageClientOptions, ServerOptions, NotificationType, Range} from "vscode-languageclient"; |
| 8 | +import * as VS from "vscode"; |
8 | 9 |
|
9 | 10 | // If we want to profile using VisualVM, we have to run the language server using regular java, not jlink |
10 | 11 | // This is intended to be used in the 'F5' debug-extension mode, where the extension is running against the actual source, not build.vsix |
@@ -171,6 +172,11 @@ interface ProgressMessage { |
171 | 172 | increment: number |
172 | 173 | } |
173 | 174 |
|
| 175 | +interface DecorationMessage { |
| 176 | + uri: string; |
| 177 | + fields: Range[] |
| 178 | +} |
| 179 | + |
174 | 180 | function createProgressListeners(client: LanguageClient) { |
175 | 181 | // Create a "checking files" progress indicator |
176 | 182 | let progressListener = new class { |
@@ -211,7 +217,30 @@ function createProgressListeners(client: LanguageClient) { |
211 | 217 | }); |
212 | 218 | client.onNotification(new NotificationType('java/endProgress'), () => { |
213 | 219 | progressListener.endProgress(); |
| 220 | + }); |
| 221 | + |
| 222 | + // Use custom notifications to do advanced syntax highlighting |
| 223 | + const fieldDecorationType = window.createTextEditorDecorationType({ |
| 224 | + color: new ThemeColor('javaFieldColor') |
214 | 225 | }); |
| 226 | + client.onNotification(new NotificationType('java/setDecorations'), (event: DecorationMessage) => { |
| 227 | + if (!window.activeTextEditor) { |
| 228 | + console.log('No active text editor'); |
| 229 | + return; |
| 230 | + } |
| 231 | + if (window.activeTextEditor.document.uri.toString() != event.uri) { |
| 232 | + console.log(`Decorations on ${event.uri} don't match open document ${window.activeTextEditor.document.uri}`); |
| 233 | + return; |
| 234 | + } |
| 235 | + const decorations: DecorationOptions[] = []; |
| 236 | + for (let field of event.fields) { |
| 237 | + const start = new VS.Position(field.start.line, field.start.character) |
| 238 | + const end = new VS.Position(field.end.line, field.end.character) |
| 239 | + const decoration = { range: new VS.Range(start, end) }; |
| 240 | + decorations.push(decoration); |
| 241 | + } |
| 242 | + window.activeTextEditor.setDecorations(fieldDecorationType, decorations); |
| 243 | + }); |
215 | 244 | } |
216 | 245 |
|
217 | 246 | function platformSpecificLauncher(): string[] { |
@@ -246,13 +275,16 @@ function visualVmConfig(context: ExtensionContext): ServerOptions { |
246 | 275 | '-Xdebug', |
247 | 276 | // '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005', |
248 | 277 | 'org.javacs.Main', |
| 278 | + // Exports, needed at compile and runtime for access |
249 | 279 | "--add-exports", "jdk.compiler/com.sun.tools.javac.api=javacs", |
250 | 280 | "--add-exports", "jdk.compiler/com.sun.tools.javac.code=javacs", |
251 | 281 | "--add-exports", "jdk.compiler/com.sun.tools.javac.comp=javacs", |
252 | 282 | "--add-exports", "jdk.compiler/com.sun.tools.javac.main=javacs", |
253 | 283 | "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=javacs", |
254 | 284 | "--add-exports", "jdk.compiler/com.sun.tools.javac.model=javacs", |
255 | 285 | "--add-exports", "jdk.compiler/com.sun.tools.javac.util=javacs", |
| 286 | + // Opens, needed at runtime for reflection |
| 287 | + "--add-opens", "jdk.compiler/com.sun.tools.javac.api=javacs", |
256 | 288 | ]; |
257 | 289 |
|
258 | 290 | console.log(javaExecutablePath + ' ' + args.join(' ')); |
|
0 commit comments