Skip to content

Commit 4e54f39

Browse files
committed
completely disable semantic token when file is too big
1 parent 31c1b21 commit 4e54f39

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

server/src/embeddedSupport/languageModes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface LanguageMode {
7474
getColorPresentations?(document: TextDocument, color: Color, range: Range): ColorPresentation[];
7575
getFoldingRanges?(document: TextDocument): FoldingRange[];
7676
getRenameFileEdit?(renames: FileRename): TextDocumentEdit[];
77-
getSemanticTokens?(document: TextDocument, range?: Range): SemanticTokenData[] | null;
77+
getSemanticTokens?(document: TextDocument, range?: Range): SemanticTokenData[];
7878

7979
onDocumentChanged?(filePath: string): void;
8080
onDocumentRemoved(document: TextDocument): void;

server/src/modes/script/javascript.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,8 @@ export async function getJavascriptMode(
804804
getSemanticTokens(doc: TextDocument, range?: Range) {
805805
const { scriptDoc, service } = updateCurrentVueTextDocument(doc);
806806
const scriptText = scriptDoc.getText();
807-
if (!range && scriptText.trim().length > SEMANTIC_TOKEN_CONTENT_LENGTH_LIMIT) {
808-
return null;
807+
if (scriptText.trim().length > SEMANTIC_TOKEN_CONTENT_LENGTH_LIMIT) {
808+
return [];
809809
}
810810

811811
const fileFsPath = getFileFsPath(doc.uri);

server/src/services/projectService.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface ProjectService {
6464
onCodeAction(params: CodeActionParams): Promise<CodeAction[]>;
6565
onCodeActionResolve(action: CodeAction): Promise<CodeAction>;
6666
onWillRenameFile(fileRename: FileRename): Promise<TextDocumentEdit[]>;
67-
onSemanticTokens(params: SemanticTokensParams | SemanticTokensRangeParams): Promise<SemanticTokens | null>;
67+
onSemanticTokens(params: SemanticTokensParams | SemanticTokensRangeParams): Promise<SemanticTokens>;
6868
doValidate(doc: TextDocument, cancellationToken?: VCancellationToken): Promise<Diagnostic[] | null>;
6969
dispose(): Promise<void>;
7070
}
@@ -356,10 +356,7 @@ export async function createProjectService(
356356

357357
for (const mode of modes) {
358358
const tokenData = mode.mode.getSemanticTokens?.(doc, range);
359-
// all or nothing
360-
if (tokenData === null) {
361-
return null;
362-
}
359+
363360
data.push(...(tokenData ?? []));
364361
}
365362

server/src/services/vls.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ export class VLS {
391391
this.lspConnection.onCodeAction(this.onCodeAction.bind(this));
392392
this.lspConnection.onCodeActionResolve(this.onCodeActionResolve.bind(this));
393393
this.lspConnection.workspace.onWillRenameFiles(this.onWillRenameFiles.bind(this));
394-
this.lspConnection.onRequest(SemanticTokensRequest.type, this.onSemanticToken.bind(this));
395-
this.lspConnection.onRequest(SemanticTokensRangeRequest.type, this.onSemanticToken.bind(this));
394+
this.lspConnection.languages.semanticTokens.on(this.onSemanticToken.bind(this));
395+
this.lspConnection.languages.semanticTokens.onRange(this.onSemanticToken.bind(this));
396396

397397
this.lspConnection.onDocumentColor(this.onDocumentColors.bind(this));
398398
this.lspConnection.onColorPresentation(this.onColorPresentations.bind(this));
@@ -629,10 +629,10 @@ export class VLS {
629629
};
630630
}
631631

632-
async onSemanticToken(params: SemanticTokensParams | SemanticTokensRangeParams): Promise<SemanticTokens | null> {
632+
async onSemanticToken(params: SemanticTokensParams | SemanticTokensRangeParams): Promise<SemanticTokens> {
633633
const project = await this.getProjectService(params.textDocument.uri);
634634

635-
return project?.onSemanticTokens(params) ?? null;
635+
return project?.onSemanticTokens(params) ?? { data: [] as number[] };
636636
}
637637

638638
private triggerValidation(textDocument: TextDocument): void {

0 commit comments

Comments
 (0)