Skip to content

Commit 9f842ac

Browse files
authored
Add use of queryTranslationUnitSource to determine if custom configuration can be skipped (#3393)
Add call in provideCustomConfiguration to new QueryTranslationUnitSourceRequest. Use result to decide whether it's necessary to request a custom configuration. * Add queryTranslationUnitSource * Update "Building the Extension.md"
1 parent e8d0ded commit 9f842ac

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

Documentation/Building the Extension.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
These steps will allow you to debug the TypeScript code that is part of the Microsoft CppTools extension for Visual Studio Code.
44

55
Prerequisite steps:
6-
* Clone [this](https://github.com/Microsoft/vscode-cpptools) repository.
6+
* Clone the release branch of [this](https://github.com/Microsoft/vscode-cpptools) repository.
7+
* git clone -b release https://github.com/Microsoft/vscode-cpptools
78
* Install [npm](https://nodejs.org).
89
* From a command line, run the following commands from the **Extension** folder in the root of the repository:
910
* `npm install` will install the dependencies needed to build the extension.

Extension/src/LanguageServer/client.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,38 @@ interface CompileCommandsPaths {
113113
paths: string[];
114114
}
115115

116+
interface QueryTranslationUnitSourceParams {
117+
uri: string;
118+
}
119+
120+
export enum QueryTranslationUnitSourceConfigDisposition {
121+
122+
/**
123+
* No custom config needed for this file
124+
*/
125+
ConfigNotNeeded = 0,
126+
127+
/**
128+
* Custom config is needed for this file
129+
*/
130+
ConfigNeeded = 1,
131+
132+
/**
133+
* Custom config is needed for the ancestor file returned in uri
134+
*/
135+
AncestorConfigNeeded = 2
136+
}
137+
138+
interface QueryTranslationUnitSourceResult {
139+
uri: string;
140+
configDisposition: QueryTranslationUnitSourceConfigDisposition;
141+
}
142+
116143
// Requests
117144
const NavigationListRequest: RequestType<TextDocumentIdentifier, string, void, void> = new RequestType<TextDocumentIdentifier, string, void, void>('cpptools/requestNavigationList');
118145
const GoToDeclarationRequest: RequestType<void, void, void, void> = new RequestType<void, void, void, void>('cpptools/goToDeclaration');
119146
const QueryCompilerDefaultsRequest: RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void> = new RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void>('cpptools/queryCompilerDefaults');
147+
const QueryTranslationUnitSourceRequest: RequestType<QueryTranslationUnitSourceParams, QueryTranslationUnitSourceResult, void, void> = new RequestType<QueryTranslationUnitSourceParams, QueryTranslationUnitSourceResult, void, void>('cpptools/queryTranslationUnitSource');
120148
const SwitchHeaderSourceRequest: RequestType<SwitchHeaderSourceParams, string, void, void> = new RequestType<SwitchHeaderSourceParams, string, void, void>('cpptools/didSwitchHeaderSource');
121149

122150
// Notifications to the server
@@ -609,6 +637,15 @@ class DefaultClient implements Client {
609637
}
610638

611639
public async provideCustomConfiguration(document: vscode.TextDocument): Promise<void> {
640+
let params: QueryTranslationUnitSourceParams = {
641+
uri: document.uri.toString()
642+
};
643+
let response: QueryTranslationUnitSourceResult = await this.languageClient.sendRequest(QueryTranslationUnitSourceRequest, params);
644+
if (response.configDisposition === QueryTranslationUnitSourceConfigDisposition.ConfigNotNeeded) {
645+
return Promise.resolve();
646+
}
647+
648+
let tuUri: vscode.Uri = vscode.Uri.parse(response.uri);
612649
let tokenSource: CancellationTokenSource = new CancellationTokenSource();
613650
let providers: CustomConfigurationProviderCollection = getCustomConfigProviders();
614651
if (providers.size === 0) {
@@ -633,8 +670,8 @@ class DefaultClient implements Client {
633670
}
634671

635672
providerName = provider.name;
636-
if (await provider.canProvideConfiguration(document.uri, tokenSource.token)) {
637-
return provider.provideConfigurations([document.uri], tokenSource.token);
673+
if (await provider.canProvideConfiguration(tuUri, tokenSource.token)) {
674+
return provider.provideConfigurations([tuUri], tokenSource.token);
638675
}
639676
}
640677
} catch (err) {
@@ -647,14 +684,19 @@ class DefaultClient implements Client {
647684
(configs: SourceFileConfigurationItem[]) => {
648685
if (configs && configs.length > 0) {
649686
this.sendCustomConfigurations(configs, true);
687+
if (response.configDisposition === QueryTranslationUnitSourceConfigDisposition.AncestorConfigNeeded) {
688+
// replacing uri with original uri
689+
let newConfig: SourceFileConfigurationItem = { uri: document.uri, configuration: configs[0].configuration };
690+
this.sendCustomConfigurations([newConfig], true);
691+
}
650692
}
651693
},
652694
(err) => {
653695
if (err === notReadyMessage) {
654696
return;
655697
}
656698
let settings: CppSettings = new CppSettings(this.RootUri);
657-
if (settings.configurationWarnings === "Enabled" && !this.isExternalHeader(document) && !vscode.debug.activeDebugSession) {
699+
if (settings.configurationWarnings === "Enabled" && !this.isExternalHeader(document.uri) && !vscode.debug.activeDebugSession) {
658700
const dismiss: string = "Dismiss";
659701
const disable: string = "Disable Warnings";
660702
let message: string = `'${providerName}' is unable to provide IntelliSense configuration information for '${document.uri.fsPath}'. ` +
@@ -675,8 +717,8 @@ class DefaultClient implements Client {
675717
});
676718
}
677719

678-
private isExternalHeader(document: vscode.TextDocument): boolean {
679-
return util.isHeader(document) && !document.uri.toString().startsWith(this.RootUri.toString());
720+
private isExternalHeader(uri: vscode.Uri): boolean {
721+
return util.isHeader(uri) && !uri.toString().startsWith(this.RootUri.toString());
680722
}
681723

682724
private getCustomConfigurationProviderId(): Thenable<string|undefined> {

Extension/src/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ export function getVcpkgRoot(): string {
149149
* For the purposes of this function, a header file has no extension, or an extension that begins with the letter 'h'.
150150
* @param document The document to check.
151151
*/
152-
export function isHeader(document: vscode.TextDocument): boolean {
153-
let ext: string = path.extname(document.uri.fsPath);
152+
export function isHeader(uri: vscode.Uri): boolean {
153+
let ext: string = path.extname(uri.fsPath);
154154
return !ext || ext.startsWith(".h") || ext.startsWith(".H");
155155
}
156156

0 commit comments

Comments
 (0)