mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Write markdown link setting change to correct scope (#159816)
Fixes #159084 Also fixes the same issue for JS/TS
This commit is contained in:
parent
d9fd208c29
commit
c4722f1bb2
|
@ -11,7 +11,7 @@ import { registerPasteSupport } from './languageFeatures/copyPaste';
|
|||
import { registerDiagnosticSupport } from './languageFeatures/diagnostics';
|
||||
import { registerDropIntoEditorSupport } from './languageFeatures/dropIntoEditor';
|
||||
import { registerFindFileReferenceSupport } from './languageFeatures/fileReferences';
|
||||
import { registerUpdateLinksOnRename } from './languageFeatures/updatePathsOnRename';
|
||||
import { registerUpdateLinksOnRename } from './languageFeatures/linkUpdater';
|
||||
import { ILogger } from './logging';
|
||||
import { MarkdownItEngine, MdParsingProvider } from './markdownEngine';
|
||||
import { MarkdownContributionProvider } from './markdownExtensions';
|
||||
|
|
|
@ -46,7 +46,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
|
|||
|
||||
this._register(vscode.workspace.onDidRenameFiles(async (e) => {
|
||||
for (const { newUri, oldUri } of e.files) {
|
||||
const config = this.getConfiguration(newUri);
|
||||
const config = vscode.workspace.getConfiguration('markdown', newUri);
|
||||
if (!await this.shouldParticipateInLinkUpdate(config, newUri)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
|
|||
return false;
|
||||
}
|
||||
|
||||
const config = this.getConfiguration(newResources[0]);
|
||||
const config = vscode.workspace.getConfiguration('markdown', newResources[0]);
|
||||
const setting = config.get<UpdateLinksOnFileMoveSetting>(settingNames.enabled);
|
||||
switch (setting) {
|
||||
case UpdateLinksOnFileMoveSetting.Prompt:
|
||||
|
@ -102,11 +102,6 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private getConfiguration(resource: vscode.Uri) {
|
||||
return vscode.workspace.getConfiguration('markdown', resource);
|
||||
}
|
||||
|
||||
private async shouldParticipateInLinkUpdate(config: vscode.WorkspaceConfiguration, newUri: vscode.Uri): Promise<boolean> {
|
||||
const setting = config.get<UpdateLinksOnFileMoveSetting>(settingNames.enabled);
|
||||
if (setting === UpdateLinksOnFileMoveSetting.Never) {
|
||||
|
@ -179,19 +174,19 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
|
|||
return false;
|
||||
}
|
||||
case Choice.Always: {
|
||||
const config = this.getConfiguration(newResources[0]);
|
||||
const config = vscode.workspace.getConfiguration('markdown', newResources[0]);
|
||||
config.update(
|
||||
settingNames.enabled,
|
||||
UpdateLinksOnFileMoveSetting.Always,
|
||||
vscode.ConfigurationTarget.Global);
|
||||
this.getConfigTargetScope(config, settingNames.enabled));
|
||||
return true;
|
||||
}
|
||||
case Choice.Never: {
|
||||
const config = this.getConfiguration(newResources[0]);
|
||||
const config = vscode.workspace.getConfiguration('markdown', newResources[0]);
|
||||
config.update(
|
||||
settingNames.enabled,
|
||||
UpdateLinksOnFileMoveSetting.Never,
|
||||
vscode.ConfigurationTarget.Global);
|
||||
this.getConfigTargetScope(config, settingNames.enabled));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -238,6 +233,19 @@ class UpdateLinksOnFileRenameHandler extends Disposable {
|
|||
paths.push('');
|
||||
return paths.join('\n');
|
||||
}
|
||||
|
||||
private getConfigTargetScope(config: vscode.WorkspaceConfiguration, settingsName: string): vscode.ConfigurationTarget {
|
||||
const inspected = config.inspect(settingsName);
|
||||
if (inspected?.workspaceFolderValue) {
|
||||
return vscode.ConfigurationTarget.WorkspaceFolder;
|
||||
}
|
||||
|
||||
if (inspected?.workspaceValue) {
|
||||
return vscode.ConfigurationTarget.Workspace;
|
||||
}
|
||||
|
||||
return vscode.ConfigurationTarget.Global;
|
||||
}
|
||||
}
|
||||
|
||||
export function registerUpdateLinksOnRename(client: BaseLanguageClient) {
|
|
@ -199,7 +199,7 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
|
|||
config.update(
|
||||
updateImportsOnFileMoveName,
|
||||
UpdateImportsOnFileMoveSetting.Always,
|
||||
vscode.ConfigurationTarget.Global);
|
||||
this.getConfigTargetScope(config, updateImportsOnFileMoveName));
|
||||
return true;
|
||||
}
|
||||
case Choice.Never:
|
||||
|
@ -208,7 +208,7 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
|
|||
config.update(
|
||||
updateImportsOnFileMoveName,
|
||||
UpdateImportsOnFileMoveSetting.Never,
|
||||
vscode.ConfigurationTarget.Global);
|
||||
this.getConfigTargetScope(config, updateImportsOnFileMoveName));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -284,6 +284,19 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
|
|||
paths.push('');
|
||||
return paths.join('\n');
|
||||
}
|
||||
|
||||
private getConfigTargetScope(config: vscode.WorkspaceConfiguration, settingsName: string): vscode.ConfigurationTarget {
|
||||
const inspected = config.inspect(settingsName);
|
||||
if (inspected?.workspaceFolderValue) {
|
||||
return vscode.ConfigurationTarget.WorkspaceFolder;
|
||||
}
|
||||
|
||||
if (inspected?.workspaceValue) {
|
||||
return vscode.ConfigurationTarget.Workspace;
|
||||
}
|
||||
|
||||
return vscode.ConfigurationTarget.Global;
|
||||
}
|
||||
}
|
||||
|
||||
export function register(
|
||||
|
|
Loading…
Reference in a new issue