Skip to content

Commit

Permalink
fix: expand Selection does not work correctly in <template> tags
Browse files Browse the repository at this point in the history
close #1465
  • Loading branch information
johnsoncodehk committed Oct 22, 2022
1 parent 34a0b20 commit b0aa1db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
33 changes: 28 additions & 5 deletions packages/language-service/src/documentFeatures/selectionRanges.ts
Expand Up @@ -13,12 +13,35 @@ export function register(context: DocumentServiceRuntimeContext) {
context,
document,
positions,
sourceMap => !!sourceMap.embeddedFile.capabilities.foldingRange,
(positions, sourceMap) => [positions
.map(position => sourceMap.toGeneratedPosition(position))
.filter(shared.notEmpty)],
(plugin, document, positions) => positions.length ? plugin.getSelectionRanges?.(document, positions) : undefined,
sourceMap => !!sourceMap.embeddedFile.capabilities.documentFormatting,
(positions, sourceMap) => {
const result = positions
.map(position => sourceMap.toGeneratedPosition(position))
.filter(shared.notEmpty);
if (result.length) {
return [result];
}
return [];
},
(plugin, document, positions) => plugin.getSelectionRanges?.(document, positions),
(item, sourceMap) => transformSelectionRanges(item, range => sourceMap.toSourceRange(range)),
results => {
for (let i = 0; i < results[0].length; i++) {
const first = results[0][i];
let lastParent = first;
while (lastParent.parent) {
lastParent = lastParent.parent;
}
for (let j = 1; j < results.length; j++) {
const other = results[j][i];
lastParent.parent = other;
while (lastParent.parent) {
lastParent = lastParent.parent;
}
}
}
return results[0];
},
);
};
}
2 changes: 1 addition & 1 deletion packages/language-service/src/utils/featureWorkers.ts
Expand Up @@ -29,7 +29,7 @@ export async function documentArgFeatureWorker<T, K>(
document: TextDocument,
arg: K,
isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean,
transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | [K],
transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | K[],
worker: (plugin: LanguageServicePlugin, document: TextDocument, arg: K) => T,
transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap) => T | undefined,
combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>,
Expand Down

0 comments on commit b0aa1db

Please sign in to comment.