|
2 | 2 | import * as monaco from 'monaco-editor'; |
3 | 3 | import * as vscode from 'vscode-languageserver-protocol'; |
4 | 4 | import * as ts from 'typescript/lib/tsserverlibrary'; |
5 | | -import { createLanguageService, getDocumentService, type LanguageService, type LanguageServiceHost } from '@volar/vue-language-service'; |
| 5 | +import { |
| 6 | + createLanguageService, |
| 7 | + getDocumentService, |
| 8 | + // executePluginCommand, |
| 9 | + type LanguageService, |
| 10 | + type LanguageServiceHost, |
| 11 | + // type ExecutePluginCommandArgs, |
| 12 | + type ConfigurationHost |
| 13 | +} from '@volar/vue-language-service'; |
6 | 14 | import type { Ref } from 'vue'; |
7 | 15 | import { onBeforeUnmount, ref } from 'vue'; |
8 | 16 | import * as code2monaco from './code2monaco'; |
@@ -143,21 +151,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode |
143 | 151 | args: [], |
144 | 152 | newLine: '\n', |
145 | 153 | useCaseSensitiveFileNames: false, |
| 154 | + readFile: host.readFile, |
| 155 | + fileExists: host.fileExists, |
146 | 156 | write(s: string): void { |
147 | 157 | throw new Error('Function not implemented.'); |
148 | 158 | }, |
149 | | - readFile(path: string, encoding?: string): string | undefined { |
150 | | - throw new Error('Function not implemented.'); |
151 | | - }, |
152 | 159 | writeFile(path: string, data: string, writeByteOrderMark?: boolean): void { |
153 | 160 | throw new Error('Function not implemented.'); |
154 | 161 | }, |
155 | 162 | resolvePath(path: string): string { |
156 | 163 | throw new Error('Function not implemented.'); |
157 | 164 | }, |
158 | | - fileExists(path: string): boolean { |
159 | | - throw new Error('Function not implemented.'); |
160 | | - }, |
161 | 165 | directoryExists(path: string): boolean { |
162 | 166 | throw new Error('Function not implemented.'); |
163 | 167 | }, |
@@ -189,8 +193,19 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode |
189 | 193 | const tsWithAny = ts as any; |
190 | 194 | tsWithAny.setSys(sys); |
191 | 195 |
|
192 | | - const ls = createLanguageService({ typescript: ts }, host, undefined, undefined, undefined, []); |
193 | | - const ds = getDocumentService({ typescript: ts }, undefined, undefined, []); |
| 196 | + const configurationHost: ConfigurationHost = { |
| 197 | + getConfiguration<T>(seation: string): T { |
| 198 | + // disabled because it these required for doExecuteCommand implementation |
| 199 | + if (seation === 'volar.codeLens.pugTools' || seation === 'volar.codeLens.scriptSetupTools') { |
| 200 | + return false as any; |
| 201 | + } |
| 202 | + return undefined as any; |
| 203 | + }, |
| 204 | + onDidChangeConfiguration() { }, |
| 205 | + rootUris: ['/'], |
| 206 | + }; |
| 207 | + const ls = createLanguageService({ typescript: ts }, host, undefined, undefined, configurationHost, []); |
| 208 | + const ds = getDocumentService({ typescript: ts }, configurationHost, undefined, []); |
194 | 209 | disposables.value.push(ls); |
195 | 210 |
|
196 | 211 | const completionItems = new WeakMap<monaco.languages.CompletionItem, vscode.CompletionItem>(); |
@@ -521,17 +536,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode |
521 | 536 | }, |
522 | 537 | }), |
523 | 538 | // same with DefinitionProvider |
524 | | - monaco.languages.registerDeclarationProvider(lang, { |
525 | | - provideDeclaration: async (model, position) => { |
526 | | - const codeResult = await ls.findDefinition( |
527 | | - model.uri.toString(), |
528 | | - monaco2code.asPosition(position), |
529 | | - ); |
530 | | - if (codeResult) { |
531 | | - return codeResult.map(code2monaco.asLocation); |
532 | | - } |
533 | | - }, |
534 | | - }), |
| 539 | + // monaco.languages.registerDeclarationProvider(lang, { |
| 540 | + // provideDeclaration: async (model, position) => { |
| 541 | + // const codeResult = await ls.findDefinition( |
| 542 | + // model.uri.toString(), |
| 543 | + // monaco2code.asPosition(position), |
| 544 | + // ); |
| 545 | + // if (codeResult) { |
| 546 | + // return codeResult.map(code2monaco.asLocation); |
| 547 | + // } |
| 548 | + // }, |
| 549 | + // }), |
535 | 550 | monaco.languages.registerSelectionRangeProvider(lang, { |
536 | 551 | provideSelectionRanges: async (model, positions) => { |
537 | 552 | const document = getTextDocument(model); |
@@ -561,6 +576,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode |
561 | 576 | } |
562 | 577 | }, |
563 | 578 | }), |
| 579 | + // return ls.doExecuteCommand(executePluginCommand, args, { |
| 580 | + // token: {} as any, |
| 581 | + // workDoneProgress: { |
| 582 | + // begin() { }, |
| 583 | + // report() { }, |
| 584 | + // done() { }, |
| 585 | + // }, |
| 586 | + // applyEdit: (paramOrEdit) => connection.workspace.applyEdit(paramOrEdit), |
| 587 | + // sendNotification: (type, params) => connection.sendNotification(type, params), |
| 588 | + // }); |
| 589 | + // }), |
564 | 590 | ); |
565 | 591 |
|
566 | 592 | return ls; |
|
0 commit comments