diff --git a/.changeset/hot-buses-suffer.md b/.changeset/hot-buses-suffer.md new file mode 100644 index 00000000..ef3a13f1 --- /dev/null +++ b/.changeset/hot-buses-suffer.md @@ -0,0 +1,5 @@ +--- +"@marko/language-tools": patch +--- + +Add typeings for $signal variable in tags api. diff --git a/package-lock.json b/package-lock.json index b24dc2cb..bf3c2d49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9860,9 +9860,6 @@ "engines": { "vscode": "^1.80.0" } - }, - "packages/vscode/node_modules/marko-ts-plugin": { - "extraneous": true } } } diff --git a/packages/language-server/src/__tests__/fixtures/script/abort-signal/__snapshots__/abort-signal.expected/index.md b/packages/language-server/src/__tests__/fixtures/script/abort-signal/__snapshots__/abort-signal.expected/index.md new file mode 100644 index 00000000..ea244968 --- /dev/null +++ b/packages/language-server/src/__tests__/fixtures/script/abort-signal/__snapshots__/abort-signal.expected/index.md @@ -0,0 +1,21 @@ +## Hovers +### Ln 2, Col 4 +```marko + 1 | 2 | $signal.onabort = () => { + | ^ const $signal: AbortSignal + 3 | // ^? + 4 | console.log('aborted'); + 5 | }; +``` + +## Diagnostics +### Ln 1, Col 2 +```marko +> 1 | { + 3 | // ^? + 4 | console.log('aborted'); +``` + diff --git a/packages/language-server/src/__tests__/fixtures/script/abort-signal/index.marko b/packages/language-server/src/__tests__/fixtures/script/abort-signal/index.marko new file mode 100644 index 00000000..15606534 --- /dev/null +++ b/packages/language-server/src/__tests__/fixtures/script/abort-signal/index.marko @@ -0,0 +1,6 @@ + { +// ^? + console.log('aborted'); + }; +}/> diff --git a/packages/language-tools/src/extractors/script/index.ts b/packages/language-tools/src/extractors/script/index.ts index ff8adc98..b24f4b19 100644 --- a/packages/language-tools/src/extractors/script/index.ts +++ b/packages/language-tools/src/extractors/script/index.ts @@ -310,6 +310,7 @@ function ${templateName}() {\n`); const input = ${this.#getCastedType(`Input${typeArgsStr}`)}; const component = ${this.#getCastedType(`Component${typeArgsStr}`)}; const state = ${varShared("state")}(component); + const $signal = ${this.#getCastedType("AbortSignal")}; const $global = ${varShared("getGlobal")}( // @ts-expect-error We expect the compiler to error because we are checking if the MarkoRun.Context is defined. (${varShared("error")}, ${this.#getCastedType("MarkoRun.Context")})