Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f931d9

Browse files
authored
Implement provider API v2 (microsoft#2531)
* Implement provider API v2
1 parentbc6cb3e commit2f931d9

File tree

10 files changed

+363
-54
lines changed

10 files changed

+363
-54
lines changed

‎Extension/.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ install.lock
1717
*.vsix
1818

1919
# ignore vscode test
20-
.vscode-test/
20+
.vscode-test/
21+
browse*db*

‎Extension/package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Extension/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@
13961396
"minimatch":"~3.0.4",
13971397
"mkdirp":"~0.5.1",
13981398
"tmp":"~0.0.33",
1399-
"vscode-cpptools":"^1.2.2",
1399+
"vscode-cpptools":"2.1.1",
14001400
"vscode-debugadapter":"~1.24.0",
14011401
"vscode-debugprotocol":"~1.24.0",
14021402
"vscode-extension-telemetry":"~0.0.11",

‎Extension/src/LanguageServer/client.ts‎

Lines changed: 115 additions & 23 deletions
Large diffs are not rendered by default.

‎Extension/src/LanguageServer/customProviders.ts‎

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,50 @@
44
* ------------------------------------------------------------------------------------------ */
55
'use strict';
66

7-
import{CustomConfigurationProvider,Version,SourceFileConfigurationItem}from'vscode-cpptools';
7+
import{CustomConfigurationProvider,Version,SourceFileConfigurationItem,WorkspaceBrowseConfiguration}from'vscode-cpptools';
88
import*asvscodefrom'vscode';
99

1010
/**
1111
* An interface that is guaranteed to be backward compatible with version 0
1212
*/
1313
exportinterfaceCustomConfigurationProvider1extendsCustomConfigurationProvider{
14-
isValid:boolean;
15-
version:Version;
14+
isReady:boolean;
15+
readonlyisValid:boolean;
16+
readonlyversion:Version;
1617
}
1718

1819
/**
1920
* Wraps the incoming CustomConfigurationProvider so that we can treat all of them as if they were the same version (e.g. latest)
2021
*/
2122
classCustomProviderWrapperimplementsCustomConfigurationProvider1{
2223
privateprovider:CustomConfigurationProvider;
24+
private_isReady:boolean;
2325
private_version:Version;
2426

2527
constructor(provider:CustomConfigurationProvider,version:Version){
28+
this._isReady=version<Version.v2;
2629
this.provider=provider;
2730
if(provider.extensionId&&version===Version.v0){
2831
version=Version.v1;// provider implemented the new API but is interfacing with the extension using the old API version.
2932
}
3033
this._version=version;
3134
}
3235

36+
publicgetisReady():boolean{
37+
returnthis._isReady;
38+
}
39+
40+
publicsetisReady(ready:boolean){
41+
this._isReady=ready;
42+
}
43+
3344
publicgetisValid():boolean{
34-
letvalid:boolean=true;
35-
if(!this.provider.name||!this.provider.canProvideConfiguration||!this.provider.provideConfigurations){
36-
valid=false;
45+
letvalid:boolean=!!(this.provider.name&&this.provider.canProvideConfiguration&&this.provider.provideConfigurations);
46+
if(valid&&this._version>Version.v0){
47+
valid=!!(this.provider.extensionId&&this.provider.dispose);
3748
}
38-
if(this._version!==Version.v0){
39-
if(!this.provider.extensionId||!this.provider.dispose){
40-
valid=false;
41-
}
49+
if(valid&&this._version>Version.v1){
50+
valid=!!(this.provider.canProvideBrowseConfiguration&&this.provider.provideBrowseConfiguration);
4251
}
4352
returnvalid;
4453
}
@@ -63,6 +72,15 @@ class CustomProviderWrapper implements CustomConfigurationProvider1 {
6372
returnthis.provider.provideConfigurations(uris,token);
6473
}
6574

75+
publiccanProvideBrowseConfiguration(token?:vscode.CancellationToken):Thenable<boolean>{
76+
returnthis._version<Version.v2 ?Promise.resolve(false) :this.provider.canProvideBrowseConfiguration(token);
77+
}
78+
79+
publicprovideBrowseConfiguration(token?:vscode.CancellationToken):Thenable<WorkspaceBrowseConfiguration>{
80+
console.assert(this._version>=Version.v2);
81+
returnthis._version<Version.v2 ?Promise.resolve({browsePath:[]}) :this.provider.provideBrowseConfiguration(token);
82+
}
83+
6684
publicdispose():void{
6785
if(this._version!==Version.v0){
6886
this.provider.dispose();
@@ -90,6 +108,12 @@ export class CustomConfigurationProviderCollection {
90108
if(version!==Version.v0&&!provider.dispose){
91109
missing.push("'dispose'");
92110
}
111+
if(version>=Version.v2&&!provider.canProvideBrowseConfiguration){
112+
missing.push("'canProvideBrowseConfiguration'");
113+
}
114+
if(version>=Version.v2&&!provider.provideBrowseConfiguration){
115+
missing.push("'provideBrowseConfiguration'");
116+
}
93117
console.error(`CustomConfigurationProvider was not registered. The following properties are missing from the implementation:${missing.join(", ")}.`);
94118
}
95119

@@ -122,7 +146,7 @@ export class CustomConfigurationProviderCollection {
122146
letexisting:CustomProviderWrapper=this.providers.get(wrapper.extensionId);
123147
exists=(existing.version===Version.v0&&wrapper.version===Version.v0);
124148
}
125-
149+
126150
if(!exists){
127151
this.providers.set(wrapper.extensionId,wrapper);
128152
}else{

‎Extension/src/common.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ export function showReleaseNotes(): void {
169169
vscode.commands.executeCommand('vscode.previewHtml',vscode.Uri.file(getExtensionFilePath("ReleaseNotes.html")),vscode.ViewColumn.One,"C/C++ Extension Release Notes");
170170
}
171171

172+
exportfunctionisUri(input:any):input isvscode.Uri{
173+
returninput&&inputinstanceofvscode.Uri;
174+
}
175+
176+
exportfunctionisString(input:any):input isstring{
177+
returninput&&typeof(input)==="string";
178+
}
179+
180+
exportfunctionisOptionalString(input:any):input isstring|undefined{
181+
returninput===undefined||typeof(input)==="string";
182+
}
183+
184+
exportfunctionisArrayOfString(input:any):input isstring[]{
185+
returninput&&(inputinstanceofArray)&&input.every(item=>typeof(item)==="string");
186+
}
187+
188+
exportfunctionisOptionalArrayOfString(input:any):input isstring[]|undefined{
189+
returninput===undefined||((inputinstanceofArray)&&input.every(item=>typeof(item)==="string"));
190+
}
191+
172192
exportfunctionresolveVariables(input:string,additionalEnvironment:{[key:string]:string|string[]}):string{
173193
if(!input){
174194
return"";
@@ -193,9 +213,9 @@ export function resolveVariables(input: string, additionalEnvironment: {[key: st
193213
switch(varType){
194214
case"env":{
195215
letv:string|string[]=additionalEnvironment[name];
196-
if(typeofv==="string"){
216+
if(isString(v)){
197217
newValue=v;
198-
}elseif(input===match&&vinstanceofArray){
218+
}elseif(input===match&&isArrayOfString(v)){
199219
newValue=v.join(";");
200220
}
201221
if(!newValue){

‎Extension/src/cppTools.ts‎

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,107 @@
77
import{CustomConfigurationProvider,Version}from'vscode-cpptools';
88
import{CppToolsTestApi,CppToolsTestHook}from'vscode-cpptools/out/testApi';
99
import{CustomConfigurationProvider1,getCustomConfigProviders,CustomConfigurationProviderCollection}from'./LanguageServer/customProviders';
10+
import{getOutputChannel}from'./logger';
1011
import*asLanguageServerfrom'./LanguageServer/extension';
1112
import*astestfrom'./testHook';
1213

1314
exportclassCppToolsimplementsCppToolsTestApi{
1415
privateversion:Version;
1516
privateproviders:CustomConfigurationProvider1[]=[];
17+
privatetimers=newMap<string,NodeJS.Timer>();
1618

1719
constructor(version:Version){
20+
if(version>Version.latest){
21+
console.warn(`version${version} is not supported by this version of cpptools`);
22+
console.warn(` using${Version.latest} instead`);
23+
version=Version.latest;
24+
}
1825
this.version=version;
1926
}
2027

21-
registerCustomConfigurationProvider(provider:CustomConfigurationProvider):void{
28+
privateaddNotifyReadyTimer(provider:CustomConfigurationProvider1):void{
29+
if(this.version>=Version.v2){
30+
consttimeout:number=30;
31+
lettimer:NodeJS.Timer=setTimeout(()=>{
32+
console.warn(`registered provider${provider.extensionId} did not call 'notifyReady' within${timeout} seconds`);
33+
},timeout*1000);
34+
this.timers.set(provider.extensionId,timer);
35+
}
36+
}
37+
38+
privateremoveNotifyReadyTimer(provider:CustomConfigurationProvider1):void{
39+
if(this.version>=Version.v2){
40+
lettimer:NodeJS.Timer=this.timers.get(provider.extensionId);
41+
if(timer){
42+
this.timers.delete(provider.extensionId);
43+
clearTimeout(timer);
44+
}
45+
}
46+
}
47+
48+
publicgetVersion():Version{
49+
returnthis.version;
50+
}
51+
52+
publicregisterCustomConfigurationProvider(provider:CustomConfigurationProvider):void{
2253
letproviders:CustomConfigurationProviderCollection=getCustomConfigProviders();
2354
if(providers.add(provider,this.version)){
2455
letadded:CustomConfigurationProvider1=providers.get(provider);
56+
getOutputChannel().appendLine(`Custom configuration provider '${added.name}' registered`);
2557
this.providers.push(added);
2658
LanguageServer.getClients().forEach(client=>client.onRegisterCustomConfigurationProvider(added));
59+
this.addNotifyReadyTimer(added);
60+
}
61+
}
62+
63+
publicnotifyReady(provider:CustomConfigurationProvider):void{
64+
letproviders:CustomConfigurationProviderCollection=getCustomConfigProviders();
65+
letp:CustomConfigurationProvider1=providers.get(provider);
66+
67+
if(p){
68+
this.removeNotifyReadyTimer(p);
69+
p.isReady=true;
70+
LanguageServer.getClients().forEach(client=>{
71+
client.updateCustomConfigurations(p);
72+
client.updateCustomBrowseConfiguration(p);
73+
});
74+
}else{
75+
console.assert(false,"provider should be registered before signaling it's ready to provide configurations");
2776
}
2877
}
2978

30-
didChangeCustomConfiguration(provider:CustomConfigurationProvider):void{
79+
publicdidChangeCustomConfiguration(provider:CustomConfigurationProvider):void{
3180
letproviders:CustomConfigurationProviderCollection=getCustomConfigProviders();
3281
letp:CustomConfigurationProvider1=providers.get(provider);
3382

3483
if(p){
84+
console.assert(p.isReady,"didChangeCustomConfiguration was invoked before notifyReady");
3585
LanguageServer.getClients().forEach(client=>client.updateCustomConfigurations(p));
3686
}else{
3787
console.assert(false,"provider should be registered before sending config change messages");
3888
}
3989
}
4090

41-
dispose():void{
91+
publicdidChangeCustomBrowseConfiguration(provider:CustomConfigurationProvider):void{
92+
letproviders:CustomConfigurationProviderCollection=getCustomConfigProviders();
93+
letp:CustomConfigurationProvider1=providers.get(provider);
94+
95+
if(p){
96+
LanguageServer.getClients().forEach(client=>client.updateCustomBrowseConfiguration(p));
97+
}else{
98+
console.assert(false,"provider should be registered before sending config change messages");
99+
}
100+
}
101+
102+
publicdispose():void{
42103
this.providers.forEach(provider=>{
43104
getCustomConfigProviders().remove(provider);
44105
provider.dispose();
45106
});
46107
this.providers=[];
47108
}
48109

49-
getTestHook():CppToolsTestHook{
110+
publicgetTestHook():CppToolsTestHook{
50111
returntest.getTestHook();
51112
}
52113
}

‎Extension/src/cppTools1.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,35 @@ export class CppTools1 implements CppToolsTestApi, CppToolsTestExtension {
2727
caseVersion.v0:
2828
returnthis.BackupApi;
2929

30-
caseVersion.v1:
31-
returnnewCppTools(version);
32-
3330
default:
34-
thrownewRangeError(`Invalidversion:${version}`);
31+
returnnewCppTools(version);
3532
}
3633
}
3734

3835
getTestApi(version:Version):CppToolsTestApi{
3936
return<CppToolsTestApi>this.getApi(version);
4037
}
4138

39+
getVersion():Version{
40+
returnthis.BackupApi.getVersion();
41+
}
42+
4243
registerCustomConfigurationProvider(provider:CustomConfigurationProvider):void{
4344
this.BackupApi.registerCustomConfigurationProvider(provider);
4445
}
4546

47+
notifyReady(provider:CustomConfigurationProvider):void{
48+
this.BackupApi.notifyReady(provider);
49+
}
50+
4651
didChangeCustomConfiguration(provider:CustomConfigurationProvider):void{
4752
this.BackupApi.didChangeCustomConfiguration(provider);
4853
}
4954

55+
didChangeCustomBrowseConfiguration(provider:CustomConfigurationProvider):void{
56+
this.BackupApi.didChangeCustomBrowseConfiguration(provider);
57+
}
58+
5059
dispose():void{
5160
}
5261

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp