-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement hover provider for tag names
- Loading branch information
1 parent
7ebc777
commit 7bb0f9a
Showing
5 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"marko-vscode": patch | ||
"@marko/language-server": patch | ||
--- | ||
|
||
Implement hover provider for tag names. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Node } from "../../../utils/parser"; | ||
import { getDocFile } from "../../../utils/doc-file"; | ||
import type { HoverMeta, HoverResult } from "."; | ||
import getTagNameCompletion from "../util/get-tag-name-completion"; | ||
import { START_OF_FILE } from "../../../utils/utils"; | ||
import type { MarkupContent } from "vscode-languageserver"; | ||
|
||
export function OpenTagName({ | ||
document, | ||
lookup, | ||
parsed, | ||
node, | ||
}: HoverMeta<Node.OpenTagName>): HoverResult { | ||
const importer = getDocFile(document); | ||
const tag = node.parent; | ||
const range = parsed.locationAt(node); | ||
const tagDef = tag.nameText && lookup.getTag(tag.nameText); | ||
|
||
if (tagDef) { | ||
const completion = getTagNameCompletion({ | ||
tag: tagDef, | ||
range: START_OF_FILE, | ||
importer, | ||
}); | ||
return { | ||
range, | ||
contents: completion.documentation as MarkupContent, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { TextDocument } from "vscode-languageserver-textdocument"; | ||
import type { HoverParams, Hover } from "vscode-languageserver"; | ||
import { getCompilerInfo, parse } from "../../../utils/compiler"; | ||
import type { Plugin, Result } from "../../types"; | ||
import { NodeType } from "../../../utils/parser"; | ||
import { OpenTagName } from "./OpenTagName"; | ||
|
||
export type HoverResult = Result<Hover>; | ||
export interface HoverMeta<N = unknown> | ||
extends ReturnType<typeof getCompilerInfo> { | ||
document: TextDocument; | ||
params: HoverParams; | ||
parsed: ReturnType<typeof parse>; | ||
offset: number; | ||
code: string; | ||
node: N; | ||
} | ||
|
||
const handlers: Record<string, (data: HoverMeta<any>) => HoverResult> = { | ||
OpenTagName, | ||
}; | ||
|
||
export const doHover: Plugin["doHover"] = async (doc, params) => { | ||
const parsed = parse(doc); | ||
const offset = doc.offsetAt(params.position); | ||
const node = parsed.nodeAt(offset); | ||
return await handlers[NodeType[node.type]]?.({ | ||
document: doc, | ||
params, | ||
parsed, | ||
offset, | ||
node, | ||
code: doc.getText(), | ||
...getCompilerInfo(doc), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters