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

Commit9e3eecc

Browse files
authored
Add setting to enable/disable code folding provider (microsoft#5435)
1 parent5fe62db commit9e3eecc

File tree

4 files changed

+89
-61
lines changed

4 files changed

+89
-61
lines changed

‎Extension/package.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@
529529
"default":false,
530530
"description":"%c_cpp.configuration.debugger.useBacktickCommandSubstitution.description%",
531531
"scope":"window"
532+
},
533+
"C_Cpp.codeFolding": {
534+
"type":"string",
535+
"enum": [
536+
"Enabled",
537+
"Disabled"
538+
],
539+
"default":"Enabled",
540+
"description":"%c_cpp.configuration.codeFolding.description%",
541+
"scope":"resource"
532542
}
533543
}
534544
},

‎Extension/package.nls.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"c_cpp.configuration.experimentalFeatures.description":"Controls whether\"experimental\" features are usable.",
6565
"c_cpp.configuration.suggestSnippets.description":"If true, snippets are provided by the language server.",
6666
"c_cpp.configuration.enhancedColorization.description":"If enabled, code is colorized based on IntelliSense. This setting has no effect if IntelliSense is disabled or if using the Default High Contrast theme.",
67+
"c_cpp.configuration.codeFolding.description":"If enabled, code folding ranges are provided by the language server.",
6768
"c_cpp.configuration.vcpkg.enabled.markdownDescription":"Enable integration services for the [vcpkg dependency manager](https://aka.ms/vcpkg/).",
6869
"c_cpp.configuration.renameRequiresIdentifier.description":"If true, 'Rename Symbol' will require a valid C/C++ identifier.",
6970
"c_cpp.configuration.debugger.useBacktickCommandSubstitution.description":"If true, debugger shell command substitution will use obsolete backtick (`)",

‎Extension/src/LanguageServer/client.ts‎

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,59 @@ export function createNullClient(): Client {
537537
returnnewNullClient();
538538
}
539539

540+
classFoldingRangeProviderimplementsvscode.FoldingRangeProvider{
541+
privateclient:DefaultClient;
542+
constructor(client:DefaultClient){
543+
this.client=client;
544+
}
545+
provideFoldingRanges(document:vscode.TextDocument,context:vscode.FoldingContext,
546+
token:vscode.CancellationToken):Promise<vscode.FoldingRange[]>{
547+
letid:number=++abortRequestId;
548+
letparams:GetFoldingRangesParams={
549+
id:id,
550+
uri:document.uri.toString()
551+
};
552+
returnnewPromise<vscode.FoldingRange[]>((resolve,reject)=>{
553+
this.client.notifyWhenReady(()=>{
554+
this.client.languageClient.sendRequest(GetFoldingRangesRequest,params)
555+
.then((ranges)=>{
556+
if(ranges.canceled){
557+
reject();
558+
}else{
559+
letresult:vscode.FoldingRange[]=[];
560+
ranges.ranges.forEach((r)=>{
561+
letfoldingRange:vscode.FoldingRange={
562+
start:r.range.start.line,
563+
end:r.range.end.line
564+
};
565+
switch(r.kind){
566+
caseFoldingRangeKind.Comment:
567+
foldingRange.kind=vscode.FoldingRangeKind.Comment;
568+
break;
569+
caseFoldingRangeKind.Imports:
570+
foldingRange.kind=vscode.FoldingRangeKind.Imports;
571+
break;
572+
caseFoldingRangeKind.Region:
573+
foldingRange.kind=vscode.FoldingRangeKind.Region;
574+
break;
575+
default:
576+
break;
577+
}
578+
result.push(foldingRange);
579+
});
580+
resolve(result);
581+
}
582+
});
583+
token.onCancellationRequested(e=>this.client.abortRequest(id));
584+
});
585+
});
586+
}
587+
}
588+
540589
exportclassDefaultClientimplementsClient{
541590
privateinnerLanguageClient?:LanguageClient;// The "client" that launches and communicates with our language "server" process.
542591
privatedisposables:vscode.Disposable[]=[];
592+
privatecodeFoldingProviderDisposable:vscode.Disposable|undefined;
543593
privateinnerConfiguration?:configs.CppProperties;
544594
privaterootPathFileWatcher?:vscode.FileSystemWatcher;
545595
privaterootFolder?:vscode.WorkspaceFolder;
@@ -551,6 +601,10 @@ export class DefaultClient implements Client {
551601
privatevisibleRanges=newMap<string,Range[]>();
552602
privatesettingsTracker:SettingsTracker;
553603
privateconfigurationProvider?:string;
604+
privatedocumentSelector:DocumentFilter[]=[
605+
{scheme:'file',language:'cpp'},
606+
{scheme:'file',language:'c'}
607+
];
554608

555609
// The "model" that is displayed via the UI (status bar).
556610
privatemodel:ClientModel=newClientModel();
@@ -586,7 +640,7 @@ export class DefaultClient implements Client {
586640
returnthis.model.referencesCommandMode.Value;
587641
}
588642

589-
privategetlanguageClient():LanguageClient{
643+
publicgetlanguageClient():LanguageClient{
590644
if(!this.innerLanguageClient){
591645
thrownewError("Attempting to use languageClient before initialized");
592646
}
@@ -665,11 +719,6 @@ export class DefaultClient implements Client {
665719
telemetry.logLanguageServerEvent("NonDefaultInitialCppSettings",this.settingsTracker.getUserModifiedSettings());
666720
failureMessageShown=false;
667721

668-
letdocumentSelector:DocumentFilter[]=[
669-
{scheme:'file',language:'cpp'},
670-
{scheme:'file',language:'c'}
671-
];
672-
673722
classCodeActionProviderimplementsvscode.CodeActionProvider{
674723
privateclient:DefaultClient;
675724
constructor(client:DefaultClient){
@@ -994,55 +1043,6 @@ export class DefaultClient implements Client {
9941043
}
9951044
}
9961045

997-
classFoldingRangeProviderimplementsvscode.FoldingRangeProvider{
998-
privateclient:DefaultClient;
999-
constructor(client:DefaultClient){
1000-
this.client=client;
1001-
}
1002-
provideFoldingRanges(document:vscode.TextDocument,context:vscode.FoldingContext,
1003-
token:vscode.CancellationToken):Promise<vscode.FoldingRange[]>{
1004-
letid:number=++abortRequestId;
1005-
letparams:GetFoldingRangesParams={
1006-
id:id,
1007-
uri:document.uri.toString()
1008-
};
1009-
returnnewPromise<vscode.FoldingRange[]>((resolve,reject)=>{
1010-
this.client.notifyWhenReady(()=>{
1011-
this.client.languageClient.sendRequest(GetFoldingRangesRequest,params)
1012-
.then((ranges)=>{
1013-
if(ranges.canceled){
1014-
reject();
1015-
}else{
1016-
letresult:vscode.FoldingRange[]=[];
1017-
ranges.ranges.forEach((r)=>{
1018-
letfoldingRange:vscode.FoldingRange={
1019-
start:r.range.start.line,
1020-
end:r.range.end.line
1021-
};
1022-
switch(r.kind){
1023-
caseFoldingRangeKind.Comment:
1024-
foldingRange.kind=vscode.FoldingRangeKind.Comment;
1025-
break;
1026-
caseFoldingRangeKind.Imports:
1027-
foldingRange.kind=vscode.FoldingRangeKind.Imports;
1028-
break;
1029-
caseFoldingRangeKind.Region:
1030-
foldingRange.kind=vscode.FoldingRangeKind.Region;
1031-
break;
1032-
default:
1033-
break;
1034-
}
1035-
result.push(foldingRange);
1036-
});
1037-
resolve(result);
1038-
}
1039-
});
1040-
token.onCancellationRequested(e=>this.client.abortRequest(id));
1041-
});
1042-
});
1043-
}
1044-
}
1045-
10461046
if(firstClient){
10471047
workspaceReferences=newrefs.ReferencesManager(this);
10481048

@@ -1058,12 +1058,15 @@ export class DefaultClient implements Client {
10581058

10591059
this.registerFileWatcher();
10601060

1061-
this.disposables.push(vscode.languages.registerRenameProvider(documentSelector,newRenameProvider(this)));
1062-
this.disposables.push(vscode.languages.registerReferenceProvider(documentSelector,newFindAllReferencesProvider(this)));
1061+
this.disposables.push(vscode.languages.registerRenameProvider(this.documentSelector,newRenameProvider(this)));
1062+
this.disposables.push(vscode.languages.registerReferenceProvider(this.documentSelector,newFindAllReferencesProvider(this)));
10631063
this.disposables.push(vscode.languages.registerWorkspaceSymbolProvider(newWorkspaceSymbolProvider(this)));
1064-
this.disposables.push(vscode.languages.registerDocumentSymbolProvider(documentSelector,newDocumentSymbolProvider(this),undefined));
1065-
this.disposables.push(vscode.languages.registerCodeActionsProvider(documentSelector,newCodeActionProvider(this),undefined));
1066-
this.disposables.push(vscode.languages.registerFoldingRangeProvider(documentSelector,newFoldingRangeProvider(this)));
1064+
this.disposables.push(vscode.languages.registerDocumentSymbolProvider(this.documentSelector,newDocumentSymbolProvider(this),undefined));
1065+
this.disposables.push(vscode.languages.registerCodeActionsProvider(this.documentSelector,newCodeActionProvider(this),undefined));
1066+
letsettings:CppSettings=newCppSettings();
1067+
if(settings.codeFolding){
1068+
this.codeFoldingProviderDisposable=vscode.languages.registerFoldingRangeProvider(this.documentSelector,newFoldingRangeProvider(this));
1069+
}
10671070

10681071
// Listen for messages from the language server.
10691072
this.registerNotifications();
@@ -1350,6 +1353,15 @@ export class DefaultClient implements Client {
13501353
if(changedSettings["commentContinuationPatterns"]){
13511354
updateLanguageConfigurations();
13521355
}
1356+
if(changedSettings["codeFolding"]){
1357+
letsettings:CppSettings=newCppSettings();
1358+
if(settings.codeFolding){
1359+
this.codeFoldingProviderDisposable=vscode.languages.registerFoldingRangeProvider(this.documentSelector,newFoldingRangeProvider(this));
1360+
}elseif(this.codeFoldingProviderDisposable){
1361+
this.codeFoldingProviderDisposable.dispose();
1362+
this.codeFoldingProviderDisposable=undefined;
1363+
}
1364+
}
13531365
this.configuration.onDidChangeSettings();
13541366
telemetry.logLanguageServerEvent("CppSettingsChange",changedSettings,undefined);
13551367
}
@@ -2540,6 +2552,10 @@ export class DefaultClient implements Client {
25402552
returnpromise.then(()=>{
25412553
this.disposables.forEach((d)=>d.dispose());
25422554
this.disposables=[];
2555+
if(this.codeFoldingProviderDisposable){
2556+
this.codeFoldingProviderDisposable.dispose();
2557+
this.codeFoldingProviderDisposable=undefined;
2558+
}
25432559
this.model.dispose();
25442560
});
25452561
}
@@ -2594,7 +2610,7 @@ export class DefaultClient implements Client {
25942610
this.model.referencesCommandMode.Value=mode;
25952611
}
25962612

2597-
privateabortRequest(id:number):void{
2613+
publicabortRequest(id:number):void{
25982614
letparams:AbortRequestParams={
25992615
id:id
26002616
};

‎Extension/src/LanguageServer/settings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export class CppSettings extends Settings {
156156
publicgetdefaultSystemIncludePath():string[]|undefined{returnsuper.Section.get<string[]>("default.systemIncludePath");}
157157
publicgetdefaultEnableConfigurationSquiggles():boolean|undefined{returnsuper.Section.get<boolean>("default.enableConfigurationSquiggles");}
158158
publicgetuseBacktickCommandSubstitution():boolean|undefined{returnsuper.Section.get<boolean>("debugger.useBacktickCommandSubstitution");}
159+
publicgetcodeFolding():boolean{returnsuper.Section.get<string>("codeFolding")==="Enabled";}
159160

160161
publicgetenhancedColorization():boolean{
161162
returnsuper.Section.get<string>("enhancedColorization")==="Enabled"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp