Skip to content

Commit 8c07026

Browse files
committed
fix: fix plugin code actions compatibility with locale
1 parent 55f4aac commit 8c07026

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

typescript/src/codeActions/decorateProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
2020
const program = languageService.getProgram()!
2121
const sourceFile = program.getSourceFile(fileName)!
2222
processApplicableRefactors(
23-
prior.find(r => r.description === 'Extract function'),
23+
prior.find(r => r.name === 'Extract Symbol' && r.actions.some(action => action.kind?.startsWith('refactor.extract.function')))?.actions,
2424
c,
2525
positionOrRange,
2626
sourceFile,

typescript/src/codeActions/functionExtractors.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {
99
} from '../utils'
1010

1111
export const processApplicableRefactors = (
12-
refactor: ts.ApplicableRefactorInfo | undefined,
12+
refactorActions: ts.RefactorActionInfo[] | undefined,
1313
c: GetConfig,
1414
posOrRange: number | ts.TextRange,
1515
sourceFile: ts.SourceFile,
1616
) => {
17-
if (!refactor) return
18-
const functionExtractors = refactor?.actions.filter(({ notApplicableReason }) => !notApplicableReason)
17+
if (!refactorActions) return
18+
const functionExtractors = refactorActions.filter(({ notApplicableReason }) => !notApplicableReason)
1919
if (functionExtractors?.length) {
2020
const kind = functionExtractors[0]!.kind!
21-
const blockScopeRefactor = functionExtractors.find(e => e.description.startsWith('Extract to inner function in'))
21+
const blockScopeRefactor = functionExtractors.find(e => e.description.includes('inner function'))
2222
const addArrowCodeActions: ts.RefactorActionInfo[] = []
2323
if (blockScopeRefactor) {
2424
addArrowCodeActions.push({
@@ -28,9 +28,7 @@ export const processApplicableRefactors = (
2828
})
2929
}
3030
let addExtractToJsxRefactor = false
31-
const globalScopeRefactor = functionExtractors.find(e =>
32-
['Extract to function in global scope', 'Extract to function in module scope'].includes(e.description),
33-
)
31+
const globalScopeRefactor = functionExtractors.at(-1)
3432
if (globalScopeRefactor) {
3533
addArrowCodeActions.push({
3634
description: 'Extract to arrow function in global scope above',
@@ -42,16 +40,20 @@ export const processApplicableRefactors = (
4240
}
4341

4442
if (addExtractToJsxRefactor) {
45-
refactor.actions = refactor.actions.filter(action => !action.name.startsWith('function_scope'))
46-
refactor.actions.push({
43+
for (const refactorAction of refactorActions) {
44+
if (refactorAction.name.startsWith('function_scope')) {
45+
refactorAction.notApplicableReason = 'JSX Element Selected. Use Extract to JSX component'
46+
}
47+
}
48+
refactorActions.push({
4749
description: 'Extract to JSX component',
4850
kind: 'refactor.extract.jsx',
4951
name: `${globalScopeRefactor!.name}_jsx`,
5052
})
5153
return
5254
}
5355

54-
refactor.actions.push(...addArrowCodeActions)
56+
refactorActions.push(...addArrowCodeActions)
5557
}
5658
}
5759

typescript/src/completionsAtPosition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import prepareTextForEmmet from './specialCommands/prepareTextForEmmet'
1515
import switchCaseExcludeCovered from './completions/switchCaseExcludeCovered'
1616
import additionalTypesSuggestions from './completions/additionalTypesSuggestions'
1717
import boostKeywordSuggestions from './completions/boostKeywordSuggestions'
18-
import boostTextSuggestions from './completions/boostNameSuggestions'
18+
import boostNameSuggestions from './completions/boostNameSuggestions'
1919
import keywordsSpace from './completions/keywordsSpace'
2020
import jsdocDefault from './completions/jsdocDefault'
2121
import defaultHelpers from './completions/defaultHelpers'
@@ -143,7 +143,7 @@ export const getCompletionsAtPosition = (
143143
}
144144

145145
if (leftNode) {
146-
const newEntries = boostTextSuggestions(prior?.entries ?? [], position, sourceFile, leftNode, languageService)
146+
const newEntries = boostNameSuggestions(prior?.entries ?? [], position, sourceFile, leftNode, languageService)
147147
if (newEntries?.length && ensurePrior() && prior) prior.entries = newEntries
148148
}
149149

0 commit comments

Comments
 (0)