Skip to content

Commit f3abd99

Browse files
committed
fix: ensure overwritten native tags get correct types
1 parent 0119949 commit f3abd99

File tree

12 files changed

+33
-29
lines changed

12 files changed

+33
-29
lines changed

.changeset/big-jeans-itch.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@marko/language-server": patch
3+
"@marko/language-tools": patch
4+
"@marko/type-check": patch
5+
"marko-vscode": patch
6+
---
7+
8+
Fix issue where overwritten native tags were not getting the correct types.

package-lock.json

Lines changed: 3 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/language-server/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"dependencies": {
1010
"@luxass/strip-json-comments": "^1.4.0",
1111
"@marko/language-tools": "^2.5.26",
12-
"@marko/babel-utils": "^6.6.3",
1312
"@marko/compiler": "^5.39.29",
1413
"htmljs-parser": "^5.6.1",
1514
"marko": "^5.37.41",

packages/language-server/src/service/marko/definition/OpenTagName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TagDefinition } from "@marko/babel-utils";
1+
import type { TagDefinition } from "@marko/compiler/babel-utils";
22
import {
33
getLines,
44
getLocation,

packages/language-server/src/service/marko/document-symbols.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SymbolInformation, SymbolKind } from "vscode-languageserver";
33

44
import { MarkoFile, processDoc } from "../../utils/file";
55
import type { Plugin } from "../types";
6+
import { isHTML } from "./util/is-html";
67

78
export const findDocumentSymbols: Plugin["findDocumentSymbols"] = async (doc) =>
89
processDoc(doc, extractDocumentSymbols);
@@ -33,7 +34,7 @@ function extractDocumentSymbols({
3334
: node.nameText) || "<${...}>",
3435
kind:
3536
(node.nameText &&
36-
lookup.getTag(node.nameText)?.html &&
37+
isHTML(lookup.getTag(node.nameText)) &&
3738
SymbolKind.Property) ||
3839
SymbolKind.Class,
3940
location: {

packages/language-server/src/service/marko/util/get-tag-name-completion.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TagDefinition } from "@marko/babel-utils";
1+
import type { TagDefinition } from "@marko/compiler/babel-utils";
22
import path from "path";
33
import {
44
type CompletionItem,
@@ -11,6 +11,8 @@ import {
1111
} from "vscode-languageserver";
1212
import { URI } from "vscode-uri";
1313

14+
import { isHTML } from "./is-html";
15+
1416
const deprecated = [CompletionItemTag.Deprecated] as CompletionItemTag[];
1517

1618
export default function getTagNameCompletion({
@@ -35,9 +37,10 @@ export default function getTagNameCompletion({
3537
const isCoreTag =
3638
/^@?marko[/-]/.test(tag.taglibId || tag.filePath) ||
3739
nodeModuleName === "marko";
40+
const html = isHTML(tag);
3841
const documentation = {
3942
kind: MarkupKind.Markdown,
40-
value: tag.html
43+
value: html
4144
? `Built in [&lt;${tag.name}&gt;](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${tag.name}) HTML tag.`
4245
: isCoreTag
4346
? `Core Marko &lt;${tag.name}&gt; tag.`
@@ -73,7 +76,7 @@ export default function getTagNameCompletion({
7376
documentation,
7477
tags: tag.deprecated ? deprecated : undefined,
7578
insertTextFormat: autocomplete ? InsertTextFormat.Snippet : undefined,
76-
kind: tag.html ? CompletionItemKind.Property : CompletionItemKind.Class,
79+
kind: html ? CompletionItemKind.Property : CompletionItemKind.Class,
7780
textEdit: range && TextEdit.replace(range, autocomplete?.snippet || label),
7881
};
7982
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { TagDefinition } from "@marko/compiler/babel-utils";
2+
3+
export function isHTML(tag: TagDefinition | undefined) {
4+
return tag ? !(tag.types || tag.template || tag.renderer) && tag.html : false;
5+
}

packages/language-server/src/service/marko/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { DiagnosticType } from "@marko/babel-utils";
21
import type { Config } from "@marko/compiler";
2+
import { DiagnosticType } from "@marko/compiler/babel-utils";
33
import { Project } from "@marko/language-tools";
44
import path from "path";
55
import { Diagnostic, DiagnosticSeverity } from "vscode-languageserver";

packages/language-server/src/utils/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TaglibLookup } from "@marko/babel-utils";
1+
import type { TaglibLookup } from "@marko/compiler/babel-utils";
22
import { parse, type Parsed, Project } from "@marko/language-tools";
33
import path from "path";
44
import type { TextDocument } from "vscode-languageserver-textdocument";

packages/language-tools/src/extractors/script/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as t from "@babel/types";
2-
import type { TagDefinition, TaglibLookup } from "@marko/babel-utils";
2+
import type { TagDefinition, TaglibLookup } from "@marko/compiler/babel-utils";
33
import { relativeImportPath } from "relative-import-path";
44
import type TS from "typescript/lib/tsserverlibrary";
55

@@ -737,14 +737,12 @@ constructor(_?: Return) {}
737737
const tagName = tag.nameText;
738738
const renderId = this.#getRenderId(tag);
739739
const def = tagName ? this.#lookup.getTag(tagName) : undefined;
740-
const isHTML = def?.html;
741-
const importPath = !isHTML
742-
? resolveTagImport(this.#filename, def)
743-
: undefined;
740+
const importPath = resolveTagImport(this.#filename, def);
741+
const isHTML = !importPath && def?.html;
744742
let tagIdentifier: undefined | string;
745743
let isTemplate = false;
746744

747-
if (!isHTML && (!def || importPath)) {
745+
if (!def || importPath) {
748746
const isIdentifier = tagName && REG_TAG_NAME_IDENTIFIER.test(tagName);
749747
const isMarkoFile = importPath?.endsWith(".marko");
750748

0 commit comments

Comments
 (0)