Skip to content

Commit 2ce03ee

Browse files
committed
Update VS Code refactoring support for new TS 4.0 api
Adopts changes from microsoft/TypeScript#37871
1 parent f328035 commit 2ce03ee

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

extensions/typescript-language-features/src/features/fileConfigurationManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { isTypeScriptDocument } from '../utils/languageModeIds';
1313
import { equals } from '../utils/objects';
1414
import { ResourceMap } from '../utils/resourceMap';
1515

16+
namespace Experimental {
17+
// https://github.com/microsoft/TypeScript/pull/37871/
18+
export interface UserPreferences extends Proto.UserPreferences {
19+
readonly provideRefactorNotApplicableReason?: boolean;
20+
}
21+
}
22+
1623
interface FileConfiguration {
1724
readonly formatOptions: Proto.FormatCodeSettings;
1825
readonly preferences: Proto.UserPreferences;
@@ -170,14 +177,15 @@ export default class FileConfigurationManager extends Disposable {
170177
isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences',
171178
document.uri);
172179

173-
const preferences: Proto.UserPreferences = {
180+
const preferences: Experimental.UserPreferences = {
174181
quotePreference: this.getQuoteStylePreference(preferencesConfig),
175182
importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferencesConfig),
176183
importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferencesConfig),
177184
allowTextChangesInNewFiles: document.uri.scheme === fileSchemes.file,
178185
providePrefixAndSuffixTextForRename: preferencesConfig.get<boolean>('renameShorthandProperties', true) === false ? false : preferencesConfig.get<boolean>('useAliasesForRenames', true),
179186
allowRenameOfImportPath: true,
180187
includeAutomaticOptionalChainCompletions: config.get<boolean>('suggest.includeAutomaticOptionalChainCompletions', true),
188+
provideRefactorNotApplicableReason: true,
181189
};
182190

183191
return preferences;

extensions/typescript-language-features/src/features/refactor.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const localize = nls.loadMessageBundle();
2222

2323
namespace Experimental {
2424
export interface RefactorActionInfo extends Proto.RefactorActionInfo {
25-
readonly error?: string
25+
readonly notApplicableReason?: string;
2626
}
2727

2828
export type RefactorTriggerReason = 'implicit' | 'invoked';
@@ -312,16 +312,16 @@ class TypeScriptRefactorProvider implements vscode.CodeActionProvider {
312312
const codeAction = new vscode.CodeAction(action.description, TypeScriptRefactorProvider.getKind(action));
313313

314314
// https://github.com/microsoft/TypeScript/pull/37871
315-
if (action.error) {
316-
codeAction.disabled = { reason: action.error };
317-
return codeAction;
315+
if (action.notApplicableReason) {
316+
codeAction.disabled = { reason: action.notApplicableReason };
317+
} else {
318+
codeAction.command = {
319+
title: action.description,
320+
command: ApplyRefactoringCommand.ID,
321+
arguments: [document, info.name, action.name, rangeOrSelection],
322+
};
318323
}
319324

320-
codeAction.command = {
321-
title: action.description,
322-
command: ApplyRefactoringCommand.ID,
323-
arguments: [document, info.name, action.name, rangeOrSelection],
324-
};
325325
codeAction.isPreferred = TypeScriptRefactorProvider.isPreferred(action, allActions);
326326
return codeAction;
327327
}

0 commit comments

Comments
 (0)