Skip to content

Commit

Permalink
fix: organize imports code action edge range incorrect
Browse files Browse the repository at this point in the history
close ##1091
  • Loading branch information
johnsoncodehk committed Mar 21, 2022
1 parent b32be70 commit fe36c6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Expand Up @@ -30,7 +30,12 @@ export function register(context: LanguageServiceRuntimeContext) {

if (resolvedItem.edit) {

const edit = embeddedEditToSourceEdit(sourceMap.embeddedFile.lsType, false, resolvedItem.edit, context.vueDocuments, () => true);
const edit = embeddedEditToSourceEdit(
sourceMap.embeddedFile.lsType,
false,
resolvedItem.edit,
context.vueDocuments,
);

if (edit) {
resolvedItem.edit = edit;
Expand Down
Expand Up @@ -101,7 +101,12 @@ export function register(context: LanguageServiceRuntimeContext) {
return _codeAction;

if (_codeAction.edit) {
const edit = embeddedEditToSourceEdit(sourceMap.embeddedFile.lsType, false, _codeAction.edit, context.vueDocuments, () => true);
const edit = embeddedEditToSourceEdit(
sourceMap.embeddedFile.lsType,
false,
_codeAction.edit,
context.vueDocuments,
);
if (edit) {
_codeAction.edit = edit;
return _codeAction;
Expand Down
Expand Up @@ -28,7 +28,6 @@ export function register(context: LanguageServiceRuntimeContext) {
false,
workspaceEdit,
context.vueDocuments,
data => typeof data.capabilities.rename === 'object' ? data.capabilities.rename.out : !!data.capabilities.rename,
)
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/vue-language-service/src/languageFuatures/rename.ts
Expand Up @@ -138,7 +138,6 @@ export function register(context: LanguageServiceRuntimeContext) {
sourceMap?.embeddedFile.lsType === 'template' && renameFromScriptContent,
data,
context.vueDocuments,
data => typeof data.capabilities.rename === 'object' ? data.capabilities.rename.out : !!data.capabilities.rename,
);
},
(workspaceEdits) => {
Expand Down Expand Up @@ -207,7 +206,6 @@ export function embeddedEditToSourceEdit(
ignoreScriptLsResult: boolean,
tsResult: vscode.WorkspaceEdit,
vueDocuments: VueDocuments,
isValidMapping: (data: EmbeddedFileMappingData) => boolean,
) {

const vueResult: vscode.WorkspaceEdit = {};
Expand All @@ -230,7 +228,7 @@ export function embeddedEditToSourceEdit(
tsUri,
tsEdit.range.start,
tsEdit.range.end,
isValidMapping,
data => typeof data.capabilities.rename === 'object' ? data.capabilities.rename.out : !!data.capabilities.rename, // fix https://github.com/johnsoncodehk/volar/issues/1091
)) {

if (ignoreScriptLsResult) {
Expand Down Expand Up @@ -277,7 +275,11 @@ export function embeddedEditToSourceEdit(
[],
);
for (const tsEdit of tsDocEdit.edits) {
for (const [vueRange, data] of sourceMap.getSourceRanges(tsEdit.range.start, tsEdit.range.end, isValidMapping)) {
for (const [vueRange, data] of sourceMap.getSourceRanges(
tsEdit.range.start,
tsEdit.range.end,
data => typeof data.capabilities.rename === 'object' ? data.capabilities.rename.out : !!data.capabilities.rename, // fix https://github.com/johnsoncodehk/volar/issues/1091
)) {

if (ignoreScriptLsResult && !(data.vueTag === 'template' || data.vueTag === 'style')) {
continue;
Expand Down

0 comments on commit fe36c6e

Please sign in to comment.