提交 2ce03eed 编写于 作者: M Matt Bierner

Update VS Code refactoring support for new TS 4.0 api

Adopts changes from https://github.com/microsoft/TypeScript/pull/37871/
上级 f3280356
......@@ -13,6 +13,13 @@ import { isTypeScriptDocument } from '../utils/languageModeIds';
import { equals } from '../utils/objects';
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 {
readonly formatOptions: Proto.FormatCodeSettings;
readonly preferences: Proto.UserPreferences;
......@@ -170,7 +177,7 @@ export default class FileConfigurationManager extends Disposable {
isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences',
document.uri);
const preferences: Proto.UserPreferences = {
const preferences: Experimental.UserPreferences = {
quotePreference: this.getQuoteStylePreference(preferencesConfig),
importModuleSpecifierPreference: getImportModuleSpecifierPreference(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),
allowRenameOfImportPath: true,
includeAutomaticOptionalChainCompletions: config.get<boolean>('suggest.includeAutomaticOptionalChainCompletions', true),
provideRefactorNotApplicableReason: true,
};
return preferences;
......
......@@ -22,7 +22,7 @@ const localize = nls.loadMessageBundle();
namespace Experimental {
export interface RefactorActionInfo extends Proto.RefactorActionInfo {
readonly error?: string
readonly notApplicableReason?: string;
}
export type RefactorTriggerReason = 'implicit' | 'invoked';
......@@ -312,16 +312,16 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
const codeAction = new vscode.CodeAction(action.description, TypeScriptRefactorProvider.getKind(action));
// https://github.com/microsoft/TypeScript/pull/37871
if (action.error) {
codeAction.disabled = { reason: action.error };
return codeAction;
if (action.notApplicableReason) {
codeAction.disabled = { reason: action.notApplicableReason };
} 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);
return codeAction;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册