Skip to content

Commit

Permalink
fix: style codeLens references always show 0
Browse files Browse the repository at this point in the history
close #1095
  • Loading branch information
johnsoncodehk committed Mar 22, 2022
1 parent 4e138d4 commit 4c048e7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 264 deletions.
Expand Up @@ -11,6 +11,7 @@ type CommandArgs = [string, vscode.Position, vscode.Location[]];

export interface ReferencesCodeLensData {
uri: string,
vueTag: string | undefined,
position: vscode.Position,
}

Expand Down Expand Up @@ -40,6 +41,7 @@ export default function (host: {

const data: ReferencesCodeLensData = {
uri: document.uri,
vueTag: mapping.data.vueTag,
position: document.positionAt(mapping.sourceRange.start),
};

Expand All @@ -65,15 +67,11 @@ export default function (host: {
if (!vueDocument)
return codeLens;

const sourceMap = vueDocument.getSourceMaps().find(sourceMap => !!sourceMap.getMappedRange(data.position));

if (!sourceMap)
return codeLens;

const sourceMaps = vueDocument.getSourceMaps();
const references = await host.findReference(data.uri, data.position) ?? [];
const referencesInDifferentDocument = references.filter(reference =>
reference.uri !== data.uri // different file
|| !sourceMap.getMappedRange(reference.range.start, reference.range.end) // different embedded document
|| !sourceMaps.some(sourceMap => sourceMap.getMappedRange(reference.range.start, reference.range.end, _data => _data.vueTag !== data.vueTag)) // different embedded document
);
const referencesCount = referencesInDifferentDocument.length ?? 0;

Expand Down

0 comments on commit 4c048e7

Please sign in to comment.