feat(language-server): add tag folding and linked editing
This commit is contained in:
@@ -77,6 +77,22 @@ export function htmlFoldingRanges(
|
||||
.map((range) => ({ startLine: range.startLine, endLine: range.endLine }));
|
||||
}
|
||||
|
||||
/** Ranges of the opening and closing tag names, so renaming one renames both. */
|
||||
export function htmlLinkedEditingRanges(
|
||||
document: TextDocument,
|
||||
position: Position,
|
||||
): Array<{ start: Position; end: Position }> | null {
|
||||
if (!isInsideHtml(document, offsetAt(document.text, position))) return null;
|
||||
|
||||
const virtual = htmlDocument(document);
|
||||
const ranges = service.findLinkedEditingRanges(
|
||||
virtual,
|
||||
position,
|
||||
service.parseHTMLDocument(virtual),
|
||||
);
|
||||
return ranges && ranges.length ? ranges : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects `<Name attr="x" /` just before `position` and completes the `>`.
|
||||
*
|
||||
|
||||
@@ -19,7 +19,13 @@ import {
|
||||
htmlToWrn,
|
||||
type TextDocument,
|
||||
} from "./index.ts";
|
||||
import { htmlCompletions, htmlHover, mergeCompletions } from "./html-service.ts";
|
||||
import {
|
||||
htmlCompletions,
|
||||
htmlFoldingRanges,
|
||||
htmlHover,
|
||||
htmlLinkedEditingRanges,
|
||||
mergeCompletions,
|
||||
} from "./html-service.ts";
|
||||
import { clearHtmlRegionCache } from "./html-regions.ts";
|
||||
|
||||
type JsonRpc = { jsonrpc?: string; id?: number | string; method?: string; params?: any };
|
||||
@@ -117,6 +123,8 @@ async function handle(message: JsonRpc): Promise<void> {
|
||||
triggerCharacters: ["<", "@", ":", ".", " ", "=", '"', "/"],
|
||||
},
|
||||
hoverProvider: true,
|
||||
foldingRangeProvider: true,
|
||||
linkedEditingRangeProvider: true,
|
||||
definitionProvider: true,
|
||||
referencesProvider: true,
|
||||
renameProvider: { prepareProvider: true },
|
||||
@@ -223,6 +231,17 @@ async function handle(message: JsonRpc): Promise<void> {
|
||||
result(message.id, html ?? (document ? hover(document, params.position) : null));
|
||||
break;
|
||||
}
|
||||
case "textDocument/foldingRange": {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
result(message.id, document ? htmlFoldingRanges(document) : []);
|
||||
break;
|
||||
}
|
||||
case "textDocument/linkedEditingRange": {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
const ranges = document ? htmlLinkedEditingRanges(document, params.position) : null;
|
||||
result(message.id, ranges ? { ranges } : null);
|
||||
break;
|
||||
}
|
||||
case "textDocument/definition": {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
result(message.id, document ? definitionLocation(document, params.position) : null);
|
||||
|
||||
Reference in New Issue
Block a user