|
1 | | -import * as requirements from './requirements'; |
| 1 | +import { resolveRequirements } from './requirements'; |
2 | 2 |
|
3 | 3 | import { DidChangeConfigurationNotification, LanguageClientOptions } from 'vscode-languageclient'; |
4 | 4 | import { LanguageClient } from 'vscode-languageclient/node'; |
5 | | -import { ExtensionContext, commands, workspace, window, ConfigurationTarget, languages } from 'vscode'; |
| 5 | +import { ExtensionContext, commands, workspace, window, ConfigurationTarget } from 'vscode'; |
6 | 6 | import { prepareExecutable } from './quteServerStarter'; |
7 | 7 | import { registerQuteExecuteWorkspaceCommand, registerVSCodeQuteCommands, synchronizeQuteValidationButton } from '../commands/registerCommands'; |
8 | 8 | import { QuteClientCommandConstants } from '../commands/commandConstants'; |
9 | 9 | import { QuteSettings } from './settings'; |
10 | 10 | import { JavaExtensionAPI } from '../../extension'; |
11 | | -import { QuteInlayHintsProvider } from './inlayHintsProvider'; |
12 | 11 |
|
13 | | -export function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI) { |
| 12 | +export async function connectToQuteLS(context: ExtensionContext, api: JavaExtensionAPI) { |
14 | 13 | registerVSCodeQuteCommands(context); |
15 | | - |
16 | | - return requirements.resolveRequirements(api).then(requirements => { |
17 | | - const clientOptions: LanguageClientOptions = { |
18 | | - documentSelector: [ |
19 | | - { scheme: 'file', language: 'qute-html' }, |
20 | | - { scheme: 'file', language: 'qute-json' }, |
21 | | - { scheme: 'file', language: 'qute-yaml' }, |
22 | | - { scheme: 'file', language: 'qute-txt' }, |
23 | | - { scheme: 'untitled', language: 'qute-html' }, |
24 | | - { scheme: 'vscode-notebook-cell', language: 'qute-html' }, |
25 | | - { scheme: 'file', language: 'java' } |
26 | | - ], |
27 | | - // wrap with key 'settings' so it can be handled same a DidChangeConfiguration |
28 | | - initializationOptions: { |
29 | | - settings: getQuteSettings(), |
30 | | - extendedClientCapabilities: { |
31 | | - commands: { |
32 | | - commandsKind: { |
33 | | - valueSet: [ |
34 | | - QuteClientCommandConstants.OPEN_URI, |
35 | | - QuteClientCommandConstants.JAVA_DEFINTION, |
36 | | - QuteClientCommandConstants.COMMAND_CONFIGURATION_UPDATE |
37 | | - ] |
38 | | - } |
39 | | - }, |
40 | | - shouldLanguageServerExitOnShutdown: true |
41 | | - } |
42 | | - }, |
43 | | - synchronize: { |
44 | | - // preferences starting with these will trigger didChangeConfiguration |
45 | | - configurationSection: ['qute'] |
46 | | - }, |
47 | | - middleware: { |
48 | | - workspace: { |
49 | | - didChangeConfiguration: async () => { |
50 | | - // A settings.json is updated: |
51 | | - // 1. send the new Quet settings to the Qute language server |
52 | | - quteLanguageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getQuteSettings() }); |
53 | | - // 2. synchronize the Qute toggle button for validation |
54 | | - await synchronizeQuteValidationButton(window.activeTextEditor); |
| 14 | + const requirements = await resolveRequirements(api); |
| 15 | + |
| 16 | + const clientOptions: LanguageClientOptions = { |
| 17 | + documentSelector: [ |
| 18 | + { scheme: 'file', language: 'qute-html' }, |
| 19 | + { scheme: 'file', language: 'qute-json' }, |
| 20 | + { scheme: 'file', language: 'qute-yaml' }, |
| 21 | + { scheme: 'file', language: 'qute-txt' }, |
| 22 | + { scheme: 'untitled', language: 'qute-html' }, |
| 23 | + { scheme: 'vscode-notebook-cell', language: 'qute-html' }, |
| 24 | + { scheme: 'file', language: 'java' } |
| 25 | + ], |
| 26 | + // wrap with key 'settings' so it can be handled same a DidChangeConfiguration |
| 27 | + initializationOptions: { |
| 28 | + settings: getQuteSettings(), |
| 29 | + extendedClientCapabilities: { |
| 30 | + commands: { |
| 31 | + commandsKind: { |
| 32 | + valueSet: [ |
| 33 | + QuteClientCommandConstants.OPEN_URI, |
| 34 | + QuteClientCommandConstants.JAVA_DEFINTION, |
| 35 | + QuteClientCommandConstants.COMMAND_CONFIGURATION_UPDATE |
| 36 | + ] |
55 | 37 | } |
56 | 38 | } |
57 | 39 | } |
58 | | - }; |
59 | | - |
60 | | - function bindQuteRequest(request: string) { |
61 | | - quteLanguageClient.onRequest(request, async (params: any) => |
62 | | - <any>await commands.executeCommand("java.execute.workspaceCommand", request, params) |
63 | | - ); |
64 | | - } |
65 | | - |
66 | | - function bindQuteNotification(notification: string) { |
67 | | - context.subscriptions.push(commands.registerCommand(notification, (event: any) => { |
68 | | - quteLanguageClient.sendNotification(notification, event); |
69 | | - })); |
| 40 | + }, |
| 41 | + synchronize: { |
| 42 | + // preferences starting with these will trigger didChangeConfiguration |
| 43 | + configurationSection: ['qute'] |
| 44 | + }, |
| 45 | + middleware: { |
| 46 | + workspace: { |
| 47 | + didChangeConfiguration: async () => { |
| 48 | + // A settings.json is updated: |
| 49 | + // 1. send the new Quet settings to the Qute language server |
| 50 | + const result = quteLanguageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getQuteSettings() }); |
| 51 | + // 2. synchronize the Qute toggle button for validation |
| 52 | + await synchronizeQuteValidationButton(window.activeTextEditor); |
| 53 | + return result; |
| 54 | + } |
| 55 | + } |
70 | 56 | } |
| 57 | + }; |
71 | 58 |
|
72 | | - const serverOptions = prepareExecutable(requirements); |
73 | | - const quteLanguageClient = new LanguageClient('qute', 'Qute Support', serverOptions, clientOptions); |
74 | | - context.subscriptions.push(quteLanguageClient.start()); |
| 59 | + function bindQuteRequest(request: string) { |
| 60 | + quteLanguageClient.onRequest(request, async (params: any) => |
| 61 | + <any>await commands.executeCommand("java.execute.workspaceCommand", request, params) |
| 62 | + ); |
| 63 | + } |
75 | 64 |
|
76 | | - return quteLanguageClient.onReady().then(async () => { |
77 | | - bindQuteRequest('qute/template/project'); |
78 | | - bindQuteRequest('qute/template/projectDataModel'); |
79 | | - bindQuteRequest('qute/template/userTags'); |
80 | | - bindQuteRequest('qute/template/javaTypes'); |
81 | | - bindQuteRequest('qute/template/resolvedJavaType'); |
82 | | - bindQuteRequest('qute/template/javaDefinition'); |
83 | | - bindQuteRequest('qute/template/javadoc'); |
84 | | - bindQuteRequest('qute/template/generateMissingJavaMember'); |
85 | | - bindQuteRequest('qute/java/codeLens'); |
86 | | - bindQuteRequest('qute/java/diagnostics'); |
87 | | - bindQuteRequest('qute/java/documentLink'); |
88 | | - bindQuteNotification('qute/dataModelChanged'); |
| 65 | + function bindQuteNotification(notification: string) { |
| 66 | + context.subscriptions.push(commands.registerCommand(notification, (event: any) => { |
| 67 | + quteLanguageClient.sendNotification(notification, event); |
| 68 | + })); |
| 69 | + } |
89 | 70 |
|
90 | | - registerQuteExecuteWorkspaceCommand(context, quteLanguageClient); |
91 | | - // Refresh the Qute context when editor tab has the focus |
92 | | - context.subscriptions.push( |
93 | | - window.onDidChangeActiveTextEditor(async editor => { |
94 | | - await synchronizeQuteValidationButton(editor); |
95 | | - }) |
96 | | - ); |
97 | | - // Refresh the Qute context when the language id changed (HTML -> Qute HTML or Qute HTML -> HTML) |
98 | | - context.subscriptions.push( |
99 | | - workspace.onDidOpenTextDocument(async (document) => { |
100 | | - // when settings.json is updated, onDidOpenTextDocument is called, |
101 | | - // the Qute context must be refreshed only for the activate text editor. |
102 | | - if (window.activeTextEditor?.document === document) { |
103 | | - await synchronizeQuteValidationButton(window.activeTextEditor); |
104 | | - } |
105 | | - // Display the experimental Qute validation pop-up if it hasn't been displayed and a Qute file is open |
106 | | - if (!hasShownQuteValidationPopUp(context) && document.languageId.includes('qute')) { |
107 | | - showQuteValidationPopUp(context); |
108 | | - } |
109 | | - }) |
110 | | - ); |
| 71 | + const serverOptions = prepareExecutable(requirements); |
| 72 | + const quteLanguageClient = new LanguageClient('qute', 'Qute Support', serverOptions, clientOptions); |
| 73 | + await quteLanguageClient.start(); |
| 74 | + |
| 75 | + bindQuteRequest('qute/template/project'); |
| 76 | + bindQuteRequest('qute/template/projectDataModel'); |
| 77 | + bindQuteRequest('qute/template/userTags'); |
| 78 | + bindQuteRequest('qute/template/javaTypes'); |
| 79 | + bindQuteRequest('qute/template/resolvedJavaType'); |
| 80 | + bindQuteRequest('qute/template/javaDefinition'); |
| 81 | + bindQuteRequest('qute/template/javadoc'); |
| 82 | + bindQuteRequest('qute/template/generateMissingJavaMember'); |
| 83 | + bindQuteRequest('qute/java/codeLens'); |
| 84 | + bindQuteRequest('qute/java/diagnostics'); |
| 85 | + bindQuteRequest('qute/java/documentLink'); |
| 86 | + bindQuteNotification('qute/dataModelChanged'); |
| 87 | + |
| 88 | + registerQuteExecuteWorkspaceCommand(context, quteLanguageClient); |
| 89 | + // Refresh the Qute context when editor tab has the focus |
| 90 | + context.subscriptions.push( |
| 91 | + window.onDidChangeActiveTextEditor(async editor => { |
| 92 | + await synchronizeQuteValidationButton(editor); |
| 93 | + }) |
| 94 | + ); |
| 95 | + // Refresh the Qute context when the language id changed (HTML -> Qute HTML or Qute HTML -> HTML) |
| 96 | + context.subscriptions.push( |
| 97 | + workspace.onDidOpenTextDocument(async (document) => { |
| 98 | + // when settings.json is updated, onDidOpenTextDocument is called, |
| 99 | + // the Qute context must be refreshed only for the activate text editor. |
| 100 | + if (window.activeTextEditor?.document === document) { |
| 101 | + await synchronizeQuteValidationButton(window.activeTextEditor); |
| 102 | + } |
111 | 103 | // Display the experimental Qute validation pop-up if it hasn't been displayed and a Qute file is open |
112 | | - if (!hasShownQuteValidationPopUp(context)) { |
113 | | - for (const textDocument of workspace.textDocuments) { |
114 | | - if (textDocument.languageId.includes('qute')) { |
115 | | - showQuteValidationPopUp(context); |
116 | | - } |
117 | | - } |
| 104 | + if (!hasShownQuteValidationPopUp(context) && document.languageId.includes('qute')) { |
| 105 | + showQuteValidationPopUp(context); |
118 | 106 | } |
119 | | - await setQuteValidationEnabledContext(); |
120 | | - await synchronizeQuteValidationButton(window.activeTextEditor); |
121 | | - |
122 | | - const supportRegisterInlayHintsProvider = (languages as any).registerInlayHintsProvider; |
123 | | - if (supportRegisterInlayHintsProvider) { |
124 | | - context.subscriptions.push(languages.registerInlayHintsProvider(clientOptions.documentSelector, new QuteInlayHintsProvider(quteLanguageClient))); |
| 107 | + }) |
| 108 | + ); |
| 109 | + // Display the experimental Qute validation pop-up if it hasn't been displayed and a Qute file is open |
| 110 | + if (!hasShownQuteValidationPopUp(context)) { |
| 111 | + for (const textDocument of workspace.textDocuments) { |
| 112 | + if (textDocument.languageId.includes('qute')) { |
| 113 | + showQuteValidationPopUp(context); |
125 | 114 | } |
126 | | - }); |
127 | | - }); |
| 115 | + } |
| 116 | + } |
| 117 | + await setQuteValidationEnabledContext(); |
| 118 | + await synchronizeQuteValidationButton(window.activeTextEditor); |
128 | 119 | } |
129 | 120 |
|
130 | 121 | /** |
|
0 commit comments