Skip to content

Commit 1c6e646

Browse files
committed
fix: disable pug and script setup codeLens
1 parent 57345ce commit 1c6e646

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

src/monaco/code2monaco.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function asLocation(definition: vscode.LocationLink | vscode.Location): m
145145
if (vscode.LocationLink.is(definition)) {
146146
return {
147147
uri: asUri(definition.targetUri),
148-
range: asRange(definition.targetRange),
148+
range: asRange(definition.targetSelectionRange),
149149
};
150150
}
151151
else {

src/monaco/ls.ts

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
import * as monaco from 'monaco-editor';
33
import * as vscode from 'vscode-languageserver-protocol';
44
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';
614
import type { Ref } from 'vue';
715
import { onBeforeUnmount, ref } from 'vue';
816
import * as code2monaco from './code2monaco';
@@ -143,21 +151,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
143151
args: [],
144152
newLine: '\n',
145153
useCaseSensitiveFileNames: false,
154+
readFile: host.readFile,
155+
fileExists: host.fileExists,
146156
write(s: string): void {
147157
throw new Error('Function not implemented.');
148158
},
149-
readFile(path: string, encoding?: string): string | undefined {
150-
throw new Error('Function not implemented.');
151-
},
152159
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void {
153160
throw new Error('Function not implemented.');
154161
},
155162
resolvePath(path: string): string {
156163
throw new Error('Function not implemented.');
157164
},
158-
fileExists(path: string): boolean {
159-
throw new Error('Function not implemented.');
160-
},
161165
directoryExists(path: string): boolean {
162166
throw new Error('Function not implemented.');
163167
},
@@ -189,8 +193,19 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
189193
const tsWithAny = ts as any;
190194
tsWithAny.setSys(sys);
191195

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, []);
194209
disposables.value.push(ls);
195210

196211
const completionItems = new WeakMap<monaco.languages.CompletionItem, vscode.CompletionItem>();
@@ -521,17 +536,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
521536
},
522537
}),
523538
// 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+
// }),
535550
monaco.languages.registerSelectionRangeProvider(lang, {
536551
provideSelectionRanges: async (model, positions) => {
537552
const document = getTextDocument(model);
@@ -561,6 +576,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
561576
}
562577
},
563578
}),
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+
// }),
564590
);
565591

566592
return ls;

0 commit comments

Comments
 (0)