mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
Set global user preferences on updatePaths
https://github.com/Microsoft/TypeScript/issues/25739
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user