Skip to content

Commit ae14e4b

Browse files
authored
Use setTextDocumentLanguage to temporarily set language ID for CUDA sources, and headers (#7745)
1 parent ef52c25 commit ae14e4b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ interface GoToDirectiveInGroupParams {
449449
next: boolean;
450450
};
451451

452+
interface SetTemporaryTextDocumentLanguageParams {
453+
path: string;
454+
isC: boolean;
455+
isCuda: boolean;
456+
}
457+
452458
// Requests
453459
const QueryCompilerDefaultsRequest: RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void> = new RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void>('cpptools/queryCompilerDefaults');
454460
const QueryTranslationUnitSourceRequest: RequestType<QueryTranslationUnitSourceParams, QueryTranslationUnitSourceResult, void, void> = new RequestType<QueryTranslationUnitSourceParams, QueryTranslationUnitSourceResult, void, void>('cpptools/queryTranslationUnitSource');
@@ -509,6 +515,7 @@ const ShowWarningNotification: NotificationType<ShowWarningParams, void> = new N
509515
const ReportTextDocumentLanguage: NotificationType<string, void> = new NotificationType<string, void>('cpptools/reportTextDocumentLanguage');
510516
const SemanticTokensChanged: NotificationType<string, void> = new NotificationType<string, void>('cpptools/semanticTokensChanged');
511517
const IntelliSenseSetupNotification: NotificationType<IntelliSenseSetup, void> = new NotificationType<IntelliSenseSetup, void>('cpptools/IntelliSenseSetup');
518+
const SetTemporaryTextDocumentLanguageNotification: NotificationType<SetTemporaryTextDocumentLanguageParams, void> = new NotificationType<SetTemporaryTextDocumentLanguageParams, void>('cpptools/setTemporaryTextDocumentLanguage');
512519

513520
let failureMessageShown: boolean = false;
514521

@@ -1971,6 +1978,7 @@ export class DefaultClient implements Client {
19711978
this.languageClient.onNotification(ReportTextDocumentLanguage, (e) => this.setTextDocumentLanguage(e));
19721979
this.languageClient.onNotification(SemanticTokensChanged, (e) => this.semanticTokensProvider?.invalidateFile(e));
19731980
this.languageClient.onNotification(IntelliSenseSetupNotification, (e) => this.logIntellisenseSetupTime(e));
1981+
this.languageClient.onNotification(SetTemporaryTextDocumentLanguageNotification, (e) => this.setTemporaryTextDocumentLanguage(e));
19741982
setupOutputHandlers();
19751983
}
19761984

@@ -1984,6 +1992,14 @@ export class DefaultClient implements Client {
19841992
}
19851993
}
19861994

1995+
private async setTemporaryTextDocumentLanguage(params: SetTemporaryTextDocumentLanguageParams): Promise<void> {
1996+
const languageId: string = params.isC ? "c" : (params.isCuda ? "cuda-cpp" : "cpp");
1997+
const document: vscode.TextDocument = await vscode.workspace.openTextDocument(params.path);
1998+
if (!!document && document.languageId !== languageId) {
1999+
vscode.languages.setTextDocumentLanguage(document, languageId);
2000+
}
2001+
}
2002+
19872003
private associations_for_did_change?: Set<string>;
19882004

19892005
/**

0 commit comments

Comments
 (0)