Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ export interface Client {
onInterval(): void;
dispose(): Thenable<void>;
addFileAssociations(fileAssociations: string, is_c: boolean): void;
sendDidChangeSettings(settings: any): void;
}

export function createClient(allClients: ClientCollection, workspaceFolder?: vscode.WorkspaceFolder): Client {
Expand Down Expand Up @@ -1267,7 +1268,7 @@ export class DefaultClient implements Client {
return new LanguageClient(`cpptools`, serverOptions, clientOptions);
}

public sendDidChangeSettings(): void {
public sendAllSettings(): void {
let cppSettingsScoped: { [key: string]: any } = {};
// Gather the C_Cpp settings
{
Expand All @@ -1293,21 +1294,26 @@ export class DefaultClient implements Client {
tabSize: vscode.workspace.getConfiguration("editor.tabSize", this.RootUri)
},
files: {
exclude: vscode.workspace.getConfiguration("files.exclude", this.RootUri)
exclude: vscode.workspace.getConfiguration("files.exclude", this.RootUri),
associations: new OtherSettings().filesAssociations
},
search: {
exclude: vscode.workspace.getConfiguration("search.exclude", this.RootUri)
}
};

this.sendDidChangeSettings(settings);
}

public sendDidChangeSettings(settings: any): void {
// Send settings json to native side
this.notifyWhenReady(() => {
this.languageClient.sendNotification(DidChangeSettingsNotification, {settings, workspaceFolderUri: this.RootPath});
});
}

public onDidChangeSettings(event: vscode.ConfigurationChangeEvent, isFirstClient: boolean): { [key: string]: string } {
this.sendDidChangeSettings();
this.sendAllSettings();
let changedSettings: { [key: string]: string };
changedSettings = this.settingsTracker.getChangedSettings();
this.notifyWhenReady(() => {
Expand Down Expand Up @@ -1965,8 +1971,7 @@ export class DefaultClient implements Client {

// TODO: Handle new associations without a reload.
this.associations_for_did_change = new Set<string>(["c", "i", "cpp", "cc", "cxx", "c++", "cp", "hpp", "hh", "hxx", "h++", "hp", "h", "ii", "ino", "inl", "ipp", "tcc", "idl"]);
let settings: OtherSettings = new OtherSettings(this.RootUri);
let assocs: any = settings.filesAssociations;
let assocs: any = new OtherSettings().filesAssociations;
for (let assoc in assocs) {
let dotIndex: number = assoc.lastIndexOf('.');
if (dotIndex !== -1) {
Expand Down Expand Up @@ -2689,4 +2694,5 @@ class NullClient implements Client {
return Promise.resolve();
}
addFileAssociations(fileAssociations: string, is_c: boolean): void {}
sendDidChangeSettings(settings: any): void {}
}
4 changes: 2 additions & 2 deletions Extension/src/LanguageServer/clientCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class ClientCollection {
this.languageClients.set(path, newClient);
newClient.deactivate(); // e.g. prevent the current config from switching.
let defaultClient: cpptools.DefaultClient = <cpptools.DefaultClient>newClient;
defaultClient.sendDidChangeSettings();
defaultClient.sendAllSettings();
}
});
}
Expand All @@ -196,7 +196,7 @@ export class ClientCollection {
this.languageClients.set(key, newClient);
getCustomConfigProviders().forEach(provider => newClient.onRegisterCustomConfigurationProvider(provider));
let defaultClient: cpptools.DefaultClient = <cpptools.DefaultClient>newClient;
defaultClient.sendDidChangeSettings();
defaultClient.sendAllSettings();
return newClient;
}
}
Expand Down
23 changes: 17 additions & 6 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TreeNode, NodeType } from './referencesModel';
import { UI, getUI } from './ui';
import { Client } from './client';
import { ClientCollection } from './clientCollection';
import { CppSettings } from './settings';
import { CppSettings, OtherSettings } from './settings';
import { PersistentWorkspaceState, PersistentState } from './persistentState';
import { getLanguageConfig } from './languageConfig';
import { getCustomConfigProviders } from './customProviders';
Expand Down Expand Up @@ -564,20 +564,31 @@ export function processDelayedDidOpen(document: vscode.TextDocument): void {
if (!client.TrackedDocuments.has(document)) {
// If not yet tracked, process as a newly opened file. (didOpen is sent to server in client.takeOwnership()).
client.TrackedDocuments.add(document);
let finishDidOpen = (doc: vscode.TextDocument) => {
client.provideCustomConfiguration(doc.uri, undefined);
client.notifyWhenReady(() => {
client.takeOwnership(doc);
client.onDidOpenTextDocument(doc);
});
};
let languageChanged: boolean = false;
// Work around vscode treating ".C" or ".H" as c, by adding this file name to file associations as cpp
if ((document.uri.path.endsWith(".C") || document.uri.path.endsWith(".H")) && document.languageId === "c") {
let cppSettings: CppSettings = new CppSettings();
if (cppSettings.autoAddFileAssociations) {
const fileName: string = path.basename(document.uri.fsPath);
const mappingString: string = fileName + "@" + document.uri.fsPath;
client.addFileAssociations(mappingString, false);
client.sendDidChangeSettings({ files: { associations: new OtherSettings().filesAssociations }});
vscode.languages.setTextDocumentLanguage(document, "cpp").then((newDoc: vscode.TextDocument) => {
finishDidOpen(newDoc);
});
languageChanged = true;
}
}
client.provideCustomConfiguration(document.uri, undefined);
client.notifyWhenReady(() => {
client.takeOwnership(document);
client.onDidOpenTextDocument(document);
});
if (!languageChanged) {
finishDidOpen(document);
}
}
}
}
Expand Down
29 changes: 20 additions & 9 deletions Extension/src/LanguageServer/protocolFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Middleware } from 'vscode-languageclient';
import { ClientCollection } from './clientCollection';
import { Client } from './client';
import * as vscode from 'vscode';
import { CppSettings } from './settings';
import { CppSettings, OtherSettings } from './settings';
import { onDidChangeActiveTextEditor, processDelayedDidOpen } from './extension';

export function createProtocolFilter(clients: ClientCollection): Middleware {
Expand All @@ -32,22 +32,33 @@ export function createProtocolFilter(clients: ClientCollection): Middleware {
let me: Client = clients.getClientFor(document.uri);
if (clients.checkOwnership(me, document)) {
me.TrackedDocuments.add(document);
let finishDidOpen = (doc: vscode.TextDocument) => {
me.provideCustomConfiguration(doc.uri, undefined);
me.notifyWhenReady(() => {
sendMessage(doc);
me.onDidOpenTextDocument(doc);
if (editor && editor === vscode.window.activeTextEditor) {
onDidChangeActiveTextEditor(editor);
}
});
};
let languageChanged: boolean = false;
if ((document.uri.path.endsWith(".C") || document.uri.path.endsWith(".H")) && document.languageId === "c") {
let cppSettings: CppSettings = new CppSettings();
if (cppSettings.autoAddFileAssociations) {
const fileName: string = path.basename(document.uri.fsPath);
const mappingString: string = fileName + "@" + document.uri.fsPath;
me.addFileAssociations(mappingString, false);
me.sendDidChangeSettings({ files: { associations: new OtherSettings().filesAssociations }});
vscode.languages.setTextDocumentLanguage(document, "cpp").then((newDoc: vscode.TextDocument) => {
finishDidOpen(newDoc);
});
languageChanged = true;
}
}
me.provideCustomConfiguration(document.uri, undefined);
me.notifyWhenReady(() => {
sendMessage(document);
me.onDidOpenTextDocument(document);
if (editor && editor === vscode.window.activeTextEditor) {
onDidChangeActiveTextEditor(editor);
}
});
if (!languageChanged) {
finishDidOpen(document);
}
}
} else {
// NO-OP
Expand Down