Skip to content

Commit

Permalink
fix: goto definition not working for alias path without script setup
Browse files Browse the repository at this point in the history
close #2600
  • Loading branch information
johnsoncodehk committed Apr 20, 2023
1 parent ed863fb commit bd3c442
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
17 changes: 13 additions & 4 deletions packages/vue-language-core/src/generators/script.ts
Expand Up @@ -107,11 +107,12 @@ export function generate(
]);
}

// fix https://github.com/johnsoncodehk/volar/issues/1048
// fix https://github.com/johnsoncodehk/volar/issues/435
// fix https://github.com/vuejs/language-tools/issues/1048
// fix https://github.com/vuejs/language-tools/issues/435
const text = toString(codes);
const start = text.length - text.trimStart().length;
const end = text.trimEnd().length;
const end1 = text.trimEnd().length;
const end2 = text.length;
const extraMappings: SourceMaps.Mapping[] = [
{
sourceRange: [0, 0],
Expand All @@ -120,10 +121,18 @@ export function generate(
},
{
sourceRange: [0, 0],
generatedRange: [end, end],
generatedRange: [end1, end1],
data: {},
},
];
// https://github.com/vuejs/language-tools/issues/2600
if (end2 !== end1) {
extraMappings.push({
sourceRange: [0, 0],
generatedRange: [end2, end2],
data: {},
});
}

return {
codes,
Expand Down
5 changes: 3 additions & 2 deletions packages/vue-language-service/tests/findDefinition.ts
Expand Up @@ -30,9 +30,10 @@ for (const dirName of testDirs) {
position.line--;

const targetFile = path.resolve(dir, action.targetFile);
const targetDocument = TextDocument.create('', '', 0, fs.readFileSync(targetFile, 'utf8'));
const targetRange = {
start: document.positionAt(action.targeRange.start),
end: document.positionAt(action.targeRange.end),
start: targetDocument.positionAt(action.targeRange.start),
end: targetDocument.positionAt(action.targeRange.end),
};

it(`${filePath}:${position.line + 1}:${position.character + 1} => ${targetFile}:${targetRange.start.line + 1}:${targetRange.start.character + 1}`, async () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/vue-test-workspace/find-definition/#2600/entry.vue
@@ -0,0 +1,6 @@
<script setup lang="ts">
import Foo from '__FIND_DEFINITION_ROOT__/#2600/foo.vue';
// ^definition: ./foo.vue, 64, 109
Foo;
</script>
7 changes: 7 additions & 0 deletions packages/vue-test-workspace/find-definition/#2600/foo.vue
@@ -0,0 +1,7 @@
<template>
<h1>{{ msg }}</h1>
</template>

<script lang="ts">
export default defineProps<{ msg: string }>()
</script>

0 comments on commit bd3c442

Please sign in to comment.