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

Commit0e43057

Browse files
authored
Add optional identifier validation to RenameProvider (microsoft#4546)
1 parentd2d2097 commit0e43057

File tree

5 files changed

+132
-3
lines changed

5 files changed

+132
-3
lines changed

‎Extension/package.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,12 @@
562562
"default":true,
563563
"markdownDescription":"%c_cpp.configuration.vcpkg.enabled.markdownDescription%",
564564
"scope":"resource"
565+
},
566+
"C_Cpp.renameRequiresIdentifier": {
567+
"type":"boolean",
568+
"default":true,
569+
"description":"%c_cpp.configuration.renameRequiresIdentifier.description%",
570+
"scope":"application"
565571
}
566572
}
567573
},
@@ -1929,4 +1935,4 @@
19291935
"binaries": []
19301936
}
19311937
]
1932-
}
1938+
}

‎Extension/package.nls.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
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.",
6767
"c_cpp.configuration.vcpkg.enabled.markdownDescription":"Enable integration services for the [vcpkg dependency manager](https://aka.ms/vcpkg/).",
68+
"c_cpp.configuration.renameRequiresIdentifier.description":"If true, 'Rename Symbol' will require a valid C/C++ identifier.",
6869
"c_cpp.contributes.views.cppReferencesView.title":"C/C++: Other references results",
6970
"c_cpp.contributes.viewsContainers.activitybar.CppRenameActivityBar.title":"C/C++ Rename",
7071
"c_cpp.contributes.views.cppRenamePendingView.title":"PENDING RENAME",

‎Extension/src/LanguageServer/client.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,12 @@ export class DefaultClient implements Client {
697697
this.client=client;
698698
}
699699
publicasyncprovideRenameEdits(document:vscode.TextDocument,position:vscode.Position,newName:string,token:vscode.CancellationToken):Promise<vscode.WorkspaceEdit>{
700+
letsettings:CppSettings=newCppSettings();
701+
if(settings.renameRequiresIdentifier&&!util.isValidIdentifier(newName)){
702+
vscode.window.showErrorMessage(localize("invalid.identifier.for.rename","Invalid identifier provided for the Rename Symbol operation."));
703+
letworkspaceEdit:vscode.WorkspaceEdit=newvscode.WorkspaceEdit();
704+
returnPromise.resolve(workspaceEdit);
705+
}
700706
// Normally, VS Code considers rename to be an atomic operation.
701707
// If the user clicks anywhere in the document, it attempts to cancel it.
702708
// Because that prevents our rename UI, we ignore cancellation requests.

‎Extension/src/LanguageServer/settings.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ export class CppSettings extends Settings {
5050
publicgetloggingLevel():string{returnsuper.Section.get<string>("loggingLevel");}
5151
publicgetnavigationLength():number{returnsuper.Section.get<number>("navigation.length",60);}
5252
publicgetautoAddFileAssociations():boolean{returnsuper.Section.get<boolean>("autoAddFileAssociations");}
53-
publicgetworkspaceParsingPriority():boolean{returnsuper.Section.get<boolean>("workspaceParsingPriority");}
53+
publicgetworkspaceParsingPriority():string{returnsuper.Section.get<string>("workspaceParsingPriority");}
5454
publicgetworkspaceSymbols():string{returnsuper.Section.get<string>("workspaceSymbols");}
55-
publicgetexclusionPolicy():boolean{returnsuper.Section.get<boolean>("exclusionPolicy");}
55+
publicgetexclusionPolicy():string{returnsuper.Section.get<string>("exclusionPolicy");}
5656
publicgetcommentContinuationPatterns():(string|CommentPattern)[]{returnsuper.Section.get<(string|CommentPattern)[]>("commentContinuationPatterns");}
5757
publicgetconfigurationWarnings():string{returnsuper.Section.get<string>("configurationWarnings");}
5858
publicgetpreferredPathSeparator():string{returnsuper.Section.get<string>("preferredPathSeparator");}
5959
publicgetupdateChannel():string{returnsuper.Section.get<string>("updateChannel");}
6060
publicgetvcpkgEnabled():boolean{returnsuper.Section.get<boolean>("vcpkg.enabled");}
61+
publicgetrenameRequiresIdentifier():boolean{returnsuper.Section.get<boolean>("renameRequiresIdentifier");}
6162
publicgetdefaultIncludePath():string[]{returnsuper.Section.get<string[]>("default.includePath");}
6263
publicgetdefaultDefines():string[]{returnsuper.Section.get<string[]>("default.defines");}
6364
publicgetdefaultMacFrameworkPath():string[]{returnsuper.Section.get<string[]>("default.macFrameworkPath");}

‎Extension/src/common.ts‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,3 +957,118 @@ export function getLocalizedString(params: LocalizeStringParams): string {
957957
}
958958
returnindent+text;
959959
}
960+
961+
functiondecodeUCS16(input:string):number[]{
962+
letoutput:number[]=[];
963+
letcounter:number=0;
964+
letlength:number=input.length;
965+
letvalue:number;
966+
letextra:number;
967+
while(counter<length){
968+
value=input.charCodeAt(counter++);
969+
// tslint:disable-next-line: no-bitwise
970+
if((value&0xF800)===0xD800&&counter<length){
971+
// high surrogate, and there is a next character
972+
extra=input.charCodeAt(counter++);
973+
// tslint:disable-next-line: no-bitwise
974+
if((extra&0xFC00)===0xDC00){// low surrogate
975+
// tslint:disable-next-line: no-bitwise
976+
output.push(((value&0x3FF)<<10)+(extra&0x3FF)+0x10000);
977+
}else{
978+
output.push(value,extra);
979+
}
980+
}else{
981+
output.push(value);
982+
}
983+
}
984+
returnoutput;
985+
}
986+
987+
letallowedIdentifierUnicodeRanges:number[][]=[
988+
[0x0030,0x0039],// digits
989+
[0x0041,0x005A],// upper case letters
990+
[0x0061,0x007A],// lower case letters
991+
[0x00A8,0x00A8],// DIARESIS
992+
[0x00AA,0x00AA],// FEMININE ORDINAL INDICATOR
993+
[0x00AD,0x00AD],// SOFT HYPHEN
994+
[0x00AF,0x00AF],// MACRON
995+
[0x00B2,0x00B5],// SUPERSCRIPT TWO - MICRO SIGN
996+
[0x00B7,0x00BA],// MIDDLE DOT - MASCULINE ORDINAL INDICATOR
997+
[0x00BC,0x00BE],// VULGAR FRACTION ONE QUARTER - VULGAR FRACTION THREE QUARTERS
998+
[0x00C0,0x00D6],// LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
999+
[0x00D8,0x00F6],// LATIN CAPITAL LETTER O WITH STROKE - LATIN SMALL LETTER O WITH DIAERESIS
1000+
[0x00F8,0x167F],// LATIN SMALL LETTER O WITH STROKE - CANADIAN SYLLABICS BLACKFOOT W
1001+
[0x1681,0x180D],// OGHAM LETTER BEITH - MONGOLIAN FREE VARIATION SELECTOR THREE
1002+
[0x180F,0x1FFF],// SYRIAC LETTER BETH - GREEK DASIA
1003+
[0x200B,0x200D],// ZERO WIDTH SPACE - ZERO WIDTH JOINER
1004+
[0x202A,0x202E],// LEFT-TO-RIGHT EMBEDDING - RIGHT-TO-LEFT OVERRIDE
1005+
[0x203F,0x2040],// UNDERTIE - CHARACTER TIE
1006+
[0x2054,0x2054],// INVERTED UNDERTIE
1007+
[0x2060,0x218F],// WORD JOINER - TURNED DIGIT THREE
1008+
[0x2460,0x24FF],// CIRCLED DIGIT ONE - NEGATIVE CIRCLED DIGIT ZERO
1009+
[0x2776,0x2793],// DINGBAT NEGATIVE CIRCLED DIGIT ONE - DINGBAT NEGATIVE CIRCLED SANS-SERIF NUMBER TEN
1010+
[0x2C00,0x2DFF],// GLAGOLITIC CAPITAL LETTER AZU - COMBINING CYRILLIC LETTER IOTIFIED BIG YUS
1011+
[0x2E80,0x2FFF],// CJK RADICAL REPEAT - IDEOGRAPHIC DESCRIPTION CHARACTER OVERLAID
1012+
[0x3004,0x3007],// JAPANESE INDUSTRIAL STANDARD SYMBOL - IDEOGRAPHIC NUMBER ZERO
1013+
[0x3021,0x302F],// HANGZHOU NUMERAL ONE - HANGUL DOUBLE DOT TONE MARK
1014+
[0x3031,0xD7FF],// VERTICAL KANA REPEAT MARK - HANGUL JONGSEONG PHIEUPH-THIEUTH
1015+
[0xF900,0xFD3D],// CJK COMPATIBILITY IDEOGRAPH-F900 - ARABIC LIGATURE ALEF WITH FATHATAN ISOLATED FORM
1016+
[0xFD40,0xFDCF],// ARABIC LIGATURE TEH WITH JEEM WITH MEEM INITIAL FORM - ARABIC LIGATURE NOON WITH JEEM WITH YEH FINAL FORM
1017+
[0xFDF0,0xFE44],// ARABIC LIGATURE SALLA USED AS KORANIC STOP SIGN ISOLATED FORM - PRESENTATION FORM FOR VERTICAL RIGHT WHITE CORNER BRACKET
1018+
[0xFE47,0xFFFD],// PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET - REPLACEMENT CHARACTER
1019+
[0x10000,0x1FFFD],// LINEAR B SYLLABLE B008 A - CHEESE WEDGE (U+1F9C0)
1020+
[0x20000,0x2FFFD],//
1021+
[0x30000,0x3FFFD],//
1022+
[0x40000,0x4FFFD],//
1023+
[0x50000,0x5FFFD],//
1024+
[0x60000,0x6FFFD],//
1025+
[0x70000,0x7FFFD],//
1026+
[0x80000,0x8FFFD],//
1027+
[0x90000,0x9FFFD],//
1028+
[0xA0000,0xAFFFD],//
1029+
[0xB0000,0xBFFFD],//
1030+
[0xC0000,0xCFFFD],//
1031+
[0xD0000,0xDFFFD],//
1032+
[0xE0000,0xEFFFD]// LANGUAGE TAG (U+E0001) - VARIATION SELECTOR-256 (U+E01EF)
1033+
];
1034+
1035+
letdisallowedFirstCharacterIdentifierUnicodeRanges:number[][]=[
1036+
[0x0030,0x0039],// digits
1037+
[0x0300,0x036F],// COMBINING GRAVE ACCENT - COMBINING LATIN SMALL LETTER X
1038+
[0x1DC0,0x1DFF],// COMBINING DOTTED GRAVE ACCENT - COMBINING RIGHT ARROWHEAD AND DOWN ARROWHEAD BELOW
1039+
[0x20D0,0x20FF],// COMBINING LEFT HARPOON ABOVE - COMBINING ASTERISK ABOVE
1040+
[0xFE20,0xFE2F],// COMBINING LIGATURE LEFT HALF - COMBINING CYRILLIC TITLO RIGHT HALF
1041+
];
1042+
1043+
exportfunctionisValidIdentifier(candidate:string):boolean{
1044+
if(!candidate){
1045+
returnfalse;
1046+
}
1047+
letdecoded:number[]=decodeUCS16(candidate);
1048+
if(!decoded||!decoded.length){
1049+
returnfalse;
1050+
}
1051+
1052+
// Reject if first character is disallowed
1053+
for(leti:number=0;i<disallowedFirstCharacterIdentifierUnicodeRanges.length;i++){
1054+
letdisallowedCharacters:number[]=disallowedFirstCharacterIdentifierUnicodeRanges[i];
1055+
if(decoded[0]>=disallowedCharacters[0]&&decoded[0]<=disallowedCharacters[1]){
1056+
returnfalse;
1057+
}
1058+
}
1059+
1060+
for(letposition:number=0;position<decoded.length;position++){
1061+
letfound:boolean=false;
1062+
for(leti:number=0;i<allowedIdentifierUnicodeRanges.length;i++){
1063+
letallowedCharacters:number[]=allowedIdentifierUnicodeRanges[i];
1064+
if(decoded[position]>=allowedCharacters[0]&&decoded[position]<=allowedCharacters[1]){
1065+
found=true;
1066+
break;
1067+
}
1068+
}
1069+
if(!found){
1070+
returnfalse;
1071+
}
1072+
}
1073+
returntrue;
1074+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp