Update VS Code refactoring support for new TS 4.0 api
Adopts changes from https://github.com/microsoft/TypeScript/pull/37871/
This commit is contained in:
parent
f3280356e4
commit
2ce03eed5a
2 changed files with 18 additions and 10 deletions
|
@ -13,6 +13,13 @@ import { isTypeScriptDocument } from '../utils/languageModeIds';
|
||||||
import { equals } from '../utils/objects';
|
import { equals } from '../utils/objects';
|
||||||
import { ResourceMap } from '../utils/resourceMap';
|
import { ResourceMap } from '../utils/resourceMap';
|
||||||
|
|
||||||
|
namespace Experimental {
|
||||||
|
// https://github.com/microsoft/TypeScript/pull/37871/
|
||||||
|
export interface UserPreferences extends Proto.UserPreferences {
|
||||||
|
readonly provideRefactorNotApplicableReason?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface FileConfiguration {
|
interface FileConfiguration {
|
||||||
readonly formatOptions: Proto.FormatCodeSettings;
|
readonly formatOptions: Proto.FormatCodeSettings;
|
||||||
readonly preferences: Proto.UserPreferences;
|
readonly preferences: Proto.UserPreferences;
|
||||||
|
@ -170,7 +177,7 @@ export default class FileConfigurationManager extends Disposable {
|
||||||
isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences',
|
isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences',
|
||||||
document.uri);
|
document.uri);
|
||||||
|
|
||||||
const preferences: Proto.UserPreferences = {
|
const preferences: Experimental.UserPreferences = {
|
||||||
quotePreference: this.getQuoteStylePreference(preferencesConfig),
|
quotePreference: this.getQuoteStylePreference(preferencesConfig),
|
||||||
importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferencesConfig),
|
importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferencesConfig),
|
||||||
importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferencesConfig),
|
importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferencesConfig),
|
||||||
|
@ -178,6 +185,7 @@ export default class FileConfigurationManager extends Disposable {
|
||||||
providePrefixAndSuffixTextForRename: preferencesConfig.get<boolean>('renameShorthandProperties', true) === false ? false : preferencesConfig.get<boolean>('useAliasesForRenames', true),
|
providePrefixAndSuffixTextForRename: preferencesConfig.get<boolean>('renameShorthandProperties', true) === false ? false : preferencesConfig.get<boolean>('useAliasesForRenames', true),
|
||||||
allowRenameOfImportPath: true,
|
allowRenameOfImportPath: true,
|
||||||
includeAutomaticOptionalChainCompletions: config.get<boolean>('suggest.includeAutomaticOptionalChainCompletions', true),
|
includeAutomaticOptionalChainCompletions: config.get<boolean>('suggest.includeAutomaticOptionalChainCompletions', true),
|
||||||
|
provideRefactorNotApplicableReason: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
return preferences;
|
return preferences;
|
||||||
|
|
|
@ -22,7 +22,7 @@ const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
namespace Experimental {
|
namespace Experimental {
|
||||||
export interface RefactorActionInfo extends Proto.RefactorActionInfo {
|
export interface RefactorActionInfo extends Proto.RefactorActionInfo {
|
||||||
readonly error?: string
|
readonly notApplicableReason?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RefactorTriggerReason = 'implicit' | 'invoked';
|
export type RefactorTriggerReason = 'implicit' | 'invoked';
|
||||||
|
@ -312,16 +312,16 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
|
||||||
const codeAction = new vscode.CodeAction(action.description, TypeScriptRefactorProvider.getKind(action));
|
const codeAction = new vscode.CodeAction(action.description, TypeScriptRefactorProvider.getKind(action));
|
||||||
|
|
||||||
// https://github.com/microsoft/TypeScript/pull/37871
|
// https://github.com/microsoft/TypeScript/pull/37871
|
||||||
if (action.error) {
|
if (action.notApplicableReason) {
|
||||||
codeAction.disabled = { reason: action.error };
|
codeAction.disabled = { reason: action.notApplicableReason };
|
||||||
return codeAction;
|
} else {
|
||||||
|
codeAction.command = {
|
||||||
|
title: action.description,
|
||||||
|
command: ApplyRefactoringCommand.ID,
|
||||||
|
arguments: [document, info.name, action.name, rangeOrSelection],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
codeAction.command = {
|
|
||||||
title: action.description,
|
|
||||||
command: ApplyRefactoringCommand.ID,
|
|
||||||
arguments: [document, info.name, action.name, rangeOrSelection],
|
|
||||||
};
|
|
||||||
codeAction.isPreferred = TypeScriptRefactorProvider.isPreferred(action, allActions);
|
codeAction.isPreferred = TypeScriptRefactorProvider.isPreferred(action, allActions);
|
||||||
return codeAction;
|
return codeAction;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue