Skip to content

Commit

Permalink
fix: disable pug and script setup codeLens
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 9, 2022
1 parent 57345ce commit 1c6e646
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/monaco/code2monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function asLocation(definition: vscode.LocationLink | vscode.Location): m
if (vscode.LocationLink.is(definition)) {
return {
uri: asUri(definition.targetUri),
range: asRange(definition.targetRange),
range: asRange(definition.targetSelectionRange),
};
}
else {
Expand Down
66 changes: 46 additions & 20 deletions src/monaco/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
import * as monaco from 'monaco-editor';
import * as vscode from 'vscode-languageserver-protocol';
import * as ts from 'typescript/lib/tsserverlibrary';
import { createLanguageService, getDocumentService, type LanguageService, type LanguageServiceHost } from '@volar/vue-language-service';
import {
createLanguageService,
getDocumentService,
// executePluginCommand,
type LanguageService,
type LanguageServiceHost,
// type ExecutePluginCommandArgs,
type ConfigurationHost
} from '@volar/vue-language-service';
import type { Ref } from 'vue';
import { onBeforeUnmount, ref } from 'vue';
import * as code2monaco from './code2monaco';
Expand Down Expand Up @@ -143,21 +151,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
args: [],
newLine: '\n',
useCaseSensitiveFileNames: false,
readFile: host.readFile,
fileExists: host.fileExists,
write(s: string): void {
throw new Error('Function not implemented.');
},
readFile(path: string, encoding?: string): string | undefined {
throw new Error('Function not implemented.');
},
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void {
throw new Error('Function not implemented.');
},
resolvePath(path: string): string {
throw new Error('Function not implemented.');
},
fileExists(path: string): boolean {
throw new Error('Function not implemented.');
},
directoryExists(path: string): boolean {
throw new Error('Function not implemented.');
},
Expand Down Expand Up @@ -189,8 +193,19 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
const tsWithAny = ts as any;
tsWithAny.setSys(sys);

const ls = createLanguageService({ typescript: ts }, host, undefined, undefined, undefined, []);
const ds = getDocumentService({ typescript: ts }, undefined, undefined, []);
const configurationHost: ConfigurationHost = {
getConfiguration<T>(seation: string): T {
// disabled because it these required for doExecuteCommand implementation
if (seation === 'volar.codeLens.pugTools' || seation === 'volar.codeLens.scriptSetupTools') {
return false as any;
}
return undefined as any;
},
onDidChangeConfiguration() { },
rootUris: ['/'],
};
const ls = createLanguageService({ typescript: ts }, host, undefined, undefined, configurationHost, []);
const ds = getDocumentService({ typescript: ts }, configurationHost, undefined, []);
disposables.value.push(ls);

const completionItems = new WeakMap<monaco.languages.CompletionItem, vscode.CompletionItem>();
Expand Down Expand Up @@ -521,17 +536,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
},
}),
// same with DefinitionProvider
monaco.languages.registerDeclarationProvider(lang, {
provideDeclaration: async (model, position) => {
const codeResult = await ls.findDefinition(
model.uri.toString(),
monaco2code.asPosition(position),
);
if (codeResult) {
return codeResult.map(code2monaco.asLocation);
}
},
}),
// monaco.languages.registerDeclarationProvider(lang, {
// provideDeclaration: async (model, position) => {
// const codeResult = await ls.findDefinition(
// model.uri.toString(),
// monaco2code.asPosition(position),
// );
// if (codeResult) {
// return codeResult.map(code2monaco.asLocation);
// }
// },
// }),
monaco.languages.registerSelectionRangeProvider(lang, {
provideSelectionRanges: async (model, positions) => {
const document = getTextDocument(model);
Expand Down Expand Up @@ -561,6 +576,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
}
},
}),
// return ls.doExecuteCommand(executePluginCommand, args, {
// token: {} as any,
// workDoneProgress: {
// begin() { },
// report() { },
// done() { },
// },
// applyEdit: (paramOrEdit) => connection.workspace.applyEdit(paramOrEdit),
// sendNotification: (type, params) => connection.sendNotification(type, params),
// });
// }),
);

return ls;
Expand Down

0 comments on commit 1c6e646

Please sign in to comment.