Set global user preferences on updatePaths

https://github.com/Microsoft/TypeScript/issues/25739
This commit is contained in:
Matt Bierner 2018-07-26 17:35:04 -07:00
parent 21bb402655
commit 01989b1c67
2 changed files with 31 additions and 7 deletions

View file

@ -61,16 +61,24 @@ export default class FileConfigurationManager {
document: vscode.TextDocument,
token: vscode.CancellationToken
): Promise<void> {
const editor = vscode.window.visibleTextEditors.find(editor => editor.document.fileName === document.fileName);
if (editor) {
const formattingOptions = {
tabSize: editor.options.tabSize,
insertSpaces: editor.options.insertSpaces
} as vscode.FormattingOptions;
const formattingOptions = this.getFormattingOptions(document);
if (formattingOptions) {
return this.ensureConfigurationOptions(document, formattingOptions, token);
}
}
private getFormattingOptions(
document: vscode.TextDocument
): vscode.FormattingOptions | undefined {
const editor = vscode.window.visibleTextEditors.find(editor => editor.document.fileName === document.fileName);
return editor
? {
tabSize: editor.options.tabSize,
insertSpaces: editor.options.insertSpaces
} as vscode.FormattingOptions
: undefined;
}
public async ensureConfigurationOptions(
document: vscode.TextDocument,
options: vscode.FormattingOptions,
@ -95,6 +103,22 @@ export default class FileConfigurationManager {
await this.client.execute('configure', args, token);
}
public async setGlobalConfigurationFromDocument(
document: vscode.TextDocument,
token: vscode.CancellationToken,
): Promise<void> {
const formattingOptions = this.getFormattingOptions(document);
if (!formattingOptions) {
return;
}
const args: Proto.ConfigureRequestArguments = {
file: undefined /*global*/,
...this.getFileOptions(document, formattingOptions),
};
await this.client.execute('configure', args, token);
}
public reset() {
this.formatOptions.clear();
}

View file

@ -230,7 +230,7 @@ class UpdateImportsOnFileRenameHandler {
newFile: string,
) {
const isDirectoryRename = fs.lstatSync(newFile).isDirectory();
await this.fileConfigurationManager.ensureConfigurationForDocument(document, nulToken);
await this.fileConfigurationManager.setGlobalConfigurationFromDocument(document, nulToken);
const args: Proto.GetEditsForFileRenameRequestArgs & { file: string } = {
file: targetResource,