@@ -263,6 +263,7 @@ export interface Client {
263263handleAddToIncludePathCommand ( path :string ) :void ;
264264onInterval ( ) :void ;
265265dispose ( ) :Thenable < void > ;
266+ addFileAssociations ( fileAssociations :string , is_c :boolean ) :void ;
266267}
267268
268269export function createClient ( allClients :ClientCollection , workspaceFolder ?:vscode . WorkspaceFolder ) :Client {
@@ -947,7 +948,11 @@ class DefaultClient implements Client {
947948
948949// TODO: Move this code to a different place?
949950if ( cppSettings . autoAddFileAssociations && payload . navigation . startsWith ( "<def" ) ) {
950- this . addFileAssociations ( payload . navigation . substr ( 4 ) ) ;
951+ let fileAssociations :string = payload . navigation . substr ( 4 ) ;
952+ let is_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 ) ;
951956return ;
952957}
953958
@@ -961,41 +966,41 @@ class DefaultClient implements Client {
961966this . model . navigationLocation . Value = currentNavigation ;
962967}
963968
964- private addFileAssociations ( fileAssociations :string ) :void {
969+ public addFileAssociations ( fileAssociations :string , is_c : boolean ) :void {
965970let settings :OtherSettings = new OtherSettings ( this . RootUri ) ;
966971let assocs :any = settings . filesAssociations ;
967- let is_c :boolean = fileAssociations . startsWith ( "c" ) ;
968972
969- // Skip over rest of header: c>; or >;
970- fileAssociations = fileAssociations . substr ( is_c ?3 :2 ) ;
971973let filesAndPaths :string [ ] = fileAssociations . split ( ";" ) ;
972974let foundNewAssociation :boolean = false ;
973- for ( let i :number = 0 ; i < filesAndPaths . length - 1 ; ++ i ) {
975+ for ( let i :number = 0 ; i < filesAndPaths . length ; ++ i ) {
974976let fileAndPath :string [ ] = filesAndPaths [ i ] . split ( "@" ) ;
975- let file :string = fileAndPath [ 0 ] ;
976- let filePath :string = fileAndPath [ 1 ] ;
977- if ( ( file in assocs ) || ( ( "**/" + file ) in assocs ) ) {
978- continue ; // File already has an association.
979- }
980- let j :number = file . lastIndexOf ( '.' ) ;
981- if ( j !== - 1 ) {
982- let ext :string = file . substr ( j ) ;
983- if ( ( ( "*" + ext ) in assocs ) || ( ( "**/*" + ext ) in assocs ) ) {
984- continue ; // Extension already has an association.
977+ // Skip empty or malformed
978+ if ( fileAndPath . length === 2 ) {
979+ let file :string = fileAndPath [ 0 ] ;
980+ let filePath :string = fileAndPath [ 1 ] ;
981+ if ( ( file in assocs ) || ( ( "**/" + file ) in assocs ) ) {
982+ continue ; // File already has an association.
985983}
986- }
987- let foundGlobMatch : boolean = false ;
988- for ( let assoc in assocs ) {
989- if ( minimatch ( filePath , assoc ) ) {
990- foundGlobMatch = true ;
991- break ; // Assoc matched a glob pattern.
984+ let j : number = file . lastIndexOf ( '.' ) ;
985+ if ( j !== - 1 ) {
986+ let ext : string = file . substr ( j ) ;
987+ if ( ( ( "*" + ext ) in assocs ) || ( ( "**/*" + ext ) in assocs ) ) {
988+ continue ; // Extension already has an association.
989+ }
992990}
991+ let foundGlobMatch :boolean = false ;
992+ for ( let assoc in assocs ) {
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}
10001005if ( foundNewAssociation ) {
10011006settings . filesAssociations = assocs ;
@@ -1496,4 +1501,5 @@ class NullClient implements Client {
14961501this . stringEvent . dispose ( ) ;
14971502return Promise . resolve ( ) ;
14981503}
1504+ addFileAssociations ( fileAssociations :string , is_c :boolean ) :void { }
14991505}