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

Commitaa6873b

Browse files
authored
Work around vscode not treating .C files as C++ (microsoft#3536)
1 parente3ddec6 commitaa6873b

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

‎Extension/src/LanguageServer/client.ts‎

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export interface Client {
263263
handleAddToIncludePathCommand(path:string):void;
264264
onInterval():void;
265265
dispose():Thenable<void>;
266+
addFileAssociations(fileAssociations:string,is_c:boolean):void;
266267
}
267268

268269
exportfunctioncreateClient(allClients:ClientCollection,workspaceFolder?:vscode.WorkspaceFolder):Client{
@@ -947,7 +948,11 @@ class DefaultClient implements Client {
947948

948949
// TODO: Move this code to a different place?
949950
if(cppSettings.autoAddFileAssociations&&payload.navigation.startsWith("<def")){
950-
this.addFileAssociations(payload.navigation.substr(4));
951+
letfileAssociations:string=payload.navigation.substr(4);
952+
letis_c:boolean=fileAssociations.startsWith("c");
953+
// Skip over rest of header: c>; or >;
954+
fileAssociations=fileAssociations.substr(is_c ?3 :2);
955+
this.addFileAssociations(fileAssociations,is_c);
951956
return;
952957
}
953958

@@ -961,41 +966,41 @@ class DefaultClient implements Client {
961966
this.model.navigationLocation.Value=currentNavigation;
962967
}
963968

964-
privateaddFileAssociations(fileAssociations:string):void{
969+
publicaddFileAssociations(fileAssociations:string,is_c:boolean):void{
965970
letsettings:OtherSettings=newOtherSettings(this.RootUri);
966971
letassocs:any=settings.filesAssociations;
967-
letis_c:boolean=fileAssociations.startsWith("c");
968972

969-
// Skip over rest of header: c>; or >;
970-
fileAssociations=fileAssociations.substr(is_c ?3 :2);
971973
letfilesAndPaths:string[]=fileAssociations.split(";");
972974
letfoundNewAssociation:boolean=false;
973-
for(leti:number=0;i<filesAndPaths.length-1;++i){
975+
for(leti:number=0;i<filesAndPaths.length;++i){
974976
letfileAndPath:string[]=filesAndPaths[i].split("@");
975-
letfile:string=fileAndPath[0];
976-
letfilePath:string=fileAndPath[1];
977-
if((fileinassocs)||(("**/"+file)inassocs)){
978-
continue;// File already has an association.
979-
}
980-
letj:number=file.lastIndexOf('.');
981-
if(j!==-1){
982-
letext:string=file.substr(j);
983-
if((("*"+ext)inassocs)||(("**/*"+ext)inassocs)){
984-
continue;// Extension already has an association.
977+
// Skip empty or malformed
978+
if(fileAndPath.length===2){
979+
letfile:string=fileAndPath[0];
980+
letfilePath:string=fileAndPath[1];
981+
if((fileinassocs)||(("**/"+file)inassocs)){
982+
continue;// File already has an association.
985983
}
986-
}
987-
letfoundGlobMatch:boolean=false;
988-
for(letassocinassocs){
989-
if(minimatch(filePath,assoc)){
990-
foundGlobMatch=true;
991-
break;// Assoc matched a glob pattern.
984+
letj:number=file.lastIndexOf('.');
985+
if(j!==-1){
986+
letext:string=file.substr(j);
987+
if((("*"+ext)inassocs)||(("**/*"+ext)inassocs)){
988+
continue;// Extension already has an association.
989+
}
992990
}
991+
letfoundGlobMatch:boolean=false;
992+
for(letassocinassocs){
993+
if(minimatch(filePath,assoc)){
994+
foundGlobMatch=true;
995+
break;// Assoc matched a glob pattern.
996+
}
997+
}
998+
if(foundGlobMatch){
999+
continue;
1000+
}
1001+
assocs[file]=is_c ?"c" :"cpp";
1002+
foundNewAssociation=true;
9931003
}
994-
if(foundGlobMatch){
995-
continue;
996-
}
997-
assocs[file]=is_c ?"c" :"cpp";
998-
foundNewAssociation=true;
9991004
}
10001005
if(foundNewAssociation){
10011006
settings.filesAssociations=assocs;
@@ -1496,4 +1501,5 @@ class NullClient implements Client {
14961501
this.stringEvent.dispose();
14971502
returnPromise.resolve();
14981503
}
1504+
addFileAssociations(fileAssociations:string,is_c:boolean):void{}
14991505
}

‎Extension/src/LanguageServer/protocolFilter.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* ------------------------------------------------------------------------------------------ */
55
'use strict';
66

7+
import*aspathfrom'path';
78
import{Middleware}from'vscode-languageclient';
89
import{ClientCollection}from'./clientCollection';
910
import{Client}from'./client';
@@ -23,6 +24,14 @@ export function createProtocolFilter(me: Client, clients: ClientCollection): Mid
2324
didOpen:(document,sendMessage)=>{
2425
if(clients.checkOwnership(me,document)){
2526
me.TrackedDocuments.add(document);
27+
28+
// Work around vscode treating ".C" as c, by adding this file name to file associations as cpp
29+
if(document.uri.path.endsWith(".C")){
30+
letfileName:string=path.basename(document.uri.fsPath);
31+
letmappingString:string=fileName+"@"+document.uri.fsPath;
32+
me.addFileAssociations(mappingString,false);
33+
}
34+
2635
me.provideCustomConfiguration(document).then(()=>{
2736
sendMessage(document);
2837
},()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp