@tsrx/language-server 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -47,7 +47,9 @@ none.
|
|
|
47
47
|
On the `classic` backend, it uses the first `typescript` it finds:
|
|
48
48
|
|
|
49
49
|
1. The `typescript.tsdk` initialization option, when the editor passes one: the
|
|
50
|
-
`lib` folder of a TypeScript installation.
|
|
50
|
+
`lib` folder of a TypeScript installation. The `typescript` package folder
|
|
51
|
+
above it works too. When the folder does not contain TypeScript, the server
|
|
52
|
+
shows a warning that names the folder, and goes on to the next step.
|
|
51
53
|
2. The project's: `node_modules/typescript` in each open workspace folder and its
|
|
52
54
|
parent folders, the way Node finds a package. The first folder that has one
|
|
53
55
|
wins. When the editor names no folder, the server searches from the folder it
|
|
@@ -64,10 +66,10 @@ npm install -D typescript
|
|
|
64
66
|
pnpm add -D typescript
|
|
65
67
|
```
|
|
66
68
|
|
|
67
|
-
When the server
|
|
68
|
-
shows one warning that says what it found and what to do. `.tsrx` files then
|
|
69
|
-
|
|
70
|
-
outline, formatting and closing tags still work.
|
|
69
|
+
When the server does not find `typescript`, or finds TypeScript 7, it still starts
|
|
70
|
+
and shows one warning that says what it found and what to do. `.tsrx` files then
|
|
71
|
+
do not get type checking, hover or completions. TSRX compile errors, CSS in
|
|
72
|
+
`<style>`, the outline, formatting and closing tags still work.
|
|
71
73
|
|
|
72
74
|
To use another TypeScript than the one it finds, pass that TypeScript's `lib`
|
|
73
75
|
folder:
|
|
@@ -219,6 +221,44 @@ Other formatters for `.tsrx` files return no edits:
|
|
|
219
221
|
In VS Code, TSRX is the default formatter for `.tsrx` files, so neither gets in
|
|
220
222
|
the way.
|
|
221
223
|
|
|
224
|
+
## Closing tags
|
|
225
|
+
|
|
226
|
+
When you type the `>` that ends an opening tag, the server inserts the closing tag
|
|
227
|
+
after the cursor: `<div>` becomes `<div></div>`. It does not close a void element
|
|
228
|
+
such as `<br>`, a self-closing tag such as `<div />`, or a tag that is already
|
|
229
|
+
closed.
|
|
230
|
+
|
|
231
|
+
Editors ask for the closing tag in one of two ways:
|
|
232
|
+
|
|
233
|
+
- **On-type formatting** (`textDocument/onTypeFormatting`), with `>` as the only
|
|
234
|
+
trigger character. A text edit cannot move the cursor, so the cursor stays
|
|
235
|
+
between the tags only in an editor that keeps it before text inserted at the
|
|
236
|
+
cursor. Zed 1.17 or newer, Neovim and JetBrains IDEs do. The READMEs of the TSRX
|
|
237
|
+
plugins for
|
|
238
|
+
[Zed](https://github.com/tsrx-org/tsrx/tree/main/packages/zed-plugin#closing-tags),
|
|
239
|
+
[Neovim](https://github.com/tsrx-org/tsrx/tree/main/packages/nvim-plugin#closing-tags),
|
|
240
|
+
[Sublime Text](https://github.com/tsrx-org/tsrx/tree/main/packages/sublime-text-plugin#closing-tags)
|
|
241
|
+
and
|
|
242
|
+
[JetBrains IDEs](https://github.com/tsrx-org/tsrx/tree/main/packages/intellij-plugin#closing-tags)
|
|
243
|
+
say what each editor needs.
|
|
244
|
+
- **Volar's `volar/client/autoInsert` request**, which the VS Code extension
|
|
245
|
+
sends. The server answers with a snippet (`$0</div>`) that puts the cursor
|
|
246
|
+
between the tags.
|
|
247
|
+
|
|
248
|
+
To turn closing tags off, set `tsrx.autoClosingTags.enabled` to `false`. The
|
|
249
|
+
server reads it through `workspace/configuration`.
|
|
250
|
+
|
|
251
|
+
An editor that closes tags another way sets the `closeTagsOnType` initialization
|
|
252
|
+
option to `false`. The server then offers no on-type formatting, so the editor
|
|
253
|
+
does not get a second closing tag. The VS Code extension does this, because VS
|
|
254
|
+
Code's TypeScript closes the tags, or on TypeScript 7 the extension sends
|
|
255
|
+
`volar/client/autoInsert`:
|
|
256
|
+
|
|
257
|
+
```jsonc
|
|
258
|
+
// LSP initialize params
|
|
259
|
+
{ "initializationOptions": { "closeTagsOnType": false } }
|
|
260
|
+
```
|
|
261
|
+
|
|
222
262
|
## Restarts after package changes
|
|
223
263
|
|
|
224
264
|
When a `package.json` or a lockfile changes (`pnpm install`, for example), the
|
package/dist/language-server.js
CHANGED
|
@@ -6418,7 +6418,7 @@ var main_exports$1 = /* @__PURE__ */ __exportAll({
|
|
|
6418
6418
|
TextDocumentIdentifier: () => TextDocumentIdentifier,
|
|
6419
6419
|
TextDocumentItem: () => TextDocumentItem,
|
|
6420
6420
|
TextEdit: () => TextEdit,
|
|
6421
|
-
URI: () => URI$
|
|
6421
|
+
URI: () => URI$4,
|
|
6422
6422
|
VersionedTextDocumentIdentifier: () => VersionedTextDocumentIdentifier,
|
|
6423
6423
|
WorkspaceChange: () => WorkspaceChange,
|
|
6424
6424
|
WorkspaceEdit: () => WorkspaceEdit,
|
|
@@ -6427,7 +6427,7 @@ var main_exports$1 = /* @__PURE__ */ __exportAll({
|
|
|
6427
6427
|
integer: () => integer,
|
|
6428
6428
|
uinteger: () => uinteger
|
|
6429
6429
|
});
|
|
6430
|
-
var DocumentUri, URI$
|
|
6430
|
+
var DocumentUri, URI$4, integer, uinteger, Position, Range, Location, LocationLink, Color, ColorInformation, ColorPresentation, FoldingRangeKind, FoldingRange, DiagnosticRelatedInformation, DiagnosticSeverity$1, DiagnosticTag, CodeDescription, Diagnostic, Command, TextEdit, ChangeAnnotation, ChangeAnnotationIdentifier, AnnotatedTextEdit, TextDocumentEdit, CreateFile, RenameFile, DeleteFile, WorkspaceEdit, TextEditChangeImpl, SnippetTextEdit, ChangeAnnotations, WorkspaceChange, TextDocumentIdentifier, VersionedTextDocumentIdentifier, OptionalVersionedTextDocumentIdentifier, LanguageKind, TextDocumentItem, MarkupKind, MarkupContent, CompletionItemKind$1, InsertTextFormat$1, CompletionItemTag, InsertReplaceEdit, InsertTextMode, ApplyKind, CompletionItemLabelDetails, CompletionItem, CompletionList, MarkedString, Hover, ParameterInformation, SignatureInformation, DocumentHighlightKind, DocumentHighlight, SymbolKind$1, SymbolTag, SymbolInformation, WorkspaceSymbol, DocumentSymbol, CodeActionKind, CodeActionTriggerKind, CodeActionContext, CodeActionTag, CodeAction, CodeLens, FormattingOptions, DocumentLink, SelectionRange, SemanticTokenTypes, SemanticTokenModifiers, SemanticTokens, InlineValueText, InlineValueVariableLookup, InlineValueEvaluatableExpression, InlineValueContext, InlayHintKind, InlayHintLabelPart, InlayHint, StringValue, InlineCompletionItem, InlineCompletionList, InlineCompletionTriggerKind, SelectedCompletionInfo, InlineCompletionContext, WorkspaceFolder, EOL, TextDocument$1, FullTextDocument$1, Is;
|
|
6431
6431
|
var init_main$1 = __esmMin((() => {
|
|
6432
6432
|
;
|
|
6433
6433
|
(function(DocumentUri) {
|
|
@@ -6442,7 +6442,7 @@ var init_main$1 = __esmMin((() => {
|
|
|
6442
6442
|
return typeof value === "string";
|
|
6443
6443
|
}
|
|
6444
6444
|
URI.is = is;
|
|
6445
|
-
})(URI$
|
|
6445
|
+
})(URI$4 || (URI$4 = {}));
|
|
6446
6446
|
;
|
|
6447
6447
|
(function(integer) {
|
|
6448
6448
|
integer.MIN_VALUE = -2147483648;
|
|
@@ -8277,7 +8277,7 @@ var init_main$1 = __esmMin((() => {
|
|
|
8277
8277
|
(function(WorkspaceFolder) {
|
|
8278
8278
|
function is(value) {
|
|
8279
8279
|
const candidate = value;
|
|
8280
|
-
return Is.objectLiteral(candidate) && URI$
|
|
8280
|
+
return Is.objectLiteral(candidate) && URI$4.is(candidate.uri) && Is.string(candidate.name);
|
|
8281
8281
|
}
|
|
8282
8282
|
WorkspaceFolder.is = is;
|
|
8283
8283
|
})(WorkspaceFolder || (WorkspaceFolder = {}));
|
|
@@ -22522,10 +22522,12 @@ function resolve_typescript_backend({ argv = [], initializationOptions } = {}) {
|
|
|
22522
22522
|
/**
|
|
22523
22523
|
* The TypeScript installation the classic backend hosts, from the Volar-style
|
|
22524
22524
|
* `typescript.tsdk` initialization option: the absolute path of a TypeScript
|
|
22525
|
-
* `lib` directory (the one containing `typescript.js`)
|
|
22526
|
-
*
|
|
22527
|
-
*
|
|
22528
|
-
*
|
|
22525
|
+
* `lib` directory (the one containing `typescript.js`), or of the `typescript`
|
|
22526
|
+
* package directory above it. An editor may pass
|
|
22527
|
+
* the TypeScript it runs for the workspace. Without it, or when it names no
|
|
22528
|
+
* TypeScript installation, the server searches the project and then its own
|
|
22529
|
+
* location (`find_typescript`). The VS Code extension uses the plugin backend,
|
|
22530
|
+
* which loads none.
|
|
22529
22531
|
* @param {unknown} initializationOptions
|
|
22530
22532
|
* @returns {string | undefined}
|
|
22531
22533
|
*/
|
|
@@ -22543,7 +22545,9 @@ function resolve_typescript_tsdk(initializationOptions) {
|
|
|
22543
22545
|
* Finding the `typescript` package the classic backend runs, in this order:
|
|
22544
22546
|
*
|
|
22545
22547
|
* 1. the `typescript.tsdk` initialization option: an editor's choice, the `lib`
|
|
22546
|
-
* directory of a TypeScript installation
|
|
22548
|
+
* directory of a TypeScript installation or the `typescript` package directory
|
|
22549
|
+
* itself (a folder with neither is skipped, and the server warns with
|
|
22550
|
+
* `tsdk_notice`);
|
|
22547
22551
|
* 2. the project's own `typescript`: `node_modules/typescript` in each open
|
|
22548
22552
|
* workspace folder (or, when the client names none, the server's working
|
|
22549
22553
|
* directory) and its parent folders, as Node resolves a package, the first
|
|
@@ -22603,15 +22607,16 @@ function find_typescript_package(from_dir) {
|
|
|
22603
22607
|
*/
|
|
22604
22608
|
function find_typescript({ tsdk, workspace_dirs, server_dir }) {
|
|
22605
22609
|
if (tsdk !== void 0) {
|
|
22606
|
-
const
|
|
22607
|
-
const dir
|
|
22608
|
-
|
|
22609
|
-
|
|
22610
|
-
|
|
22611
|
-
|
|
22612
|
-
|
|
22613
|
-
|
|
22614
|
-
|
|
22610
|
+
const folder = node_path.default.resolve(tsdk);
|
|
22611
|
+
for (const [dir, lib] of [[node_path.default.dirname(folder), folder], [folder, node_path.default.join(folder, "lib")]]) {
|
|
22612
|
+
const version = package_version(dir);
|
|
22613
|
+
if (version !== void 0) return {
|
|
22614
|
+
dir: node_fs.default.realpathSync(dir),
|
|
22615
|
+
lib,
|
|
22616
|
+
version,
|
|
22617
|
+
source: "tsdk"
|
|
22618
|
+
};
|
|
22619
|
+
}
|
|
22615
22620
|
}
|
|
22616
22621
|
for (const workspace_dir of workspace_dirs) {
|
|
22617
22622
|
const found = find_typescript_package(workspace_dir);
|
|
@@ -22633,27 +22638,48 @@ function find_typescript({ tsdk, workspace_dirs, server_dir }) {
|
|
|
22633
22638
|
function is_usable_typescript(version) {
|
|
22634
22639
|
return Number.parseInt(version, 10) < 7;
|
|
22635
22640
|
}
|
|
22641
|
+
/** What the server does not provide without TypeScript, for the notices. */
|
|
22642
|
+
const NO_FEATURES = "The TSRX language server will not be able to provide type checking, hover or completions in .tsrx files.";
|
|
22636
22643
|
/** What still works without TypeScript, for the notices. */
|
|
22637
|
-
const STILL_WORKS = "TSRX compile errors, CSS in <style>, the outline, formatting and closing tags
|
|
22644
|
+
const STILL_WORKS = "These features still work: TSRX compile errors, CSS in <style>, the outline, formatting and closing tags.";
|
|
22645
|
+
/**
|
|
22646
|
+
* The notice the server shows when the `typescript.tsdk` option is set but
|
|
22647
|
+
* `find_typescript` skipped it: the folder has no `typescript` package.
|
|
22648
|
+
* @param {string} tsdk the option's value
|
|
22649
|
+
* @param {FoundTypeScript | undefined} found the `typescript` found instead
|
|
22650
|
+
* @returns {string}
|
|
22651
|
+
*/
|
|
22652
|
+
function tsdk_notice(tsdk, found) {
|
|
22653
|
+
const sentences = ["The TSRX language server does not use the typescript.tsdk startup option.", `The folder in this option does not contain TypeScript: ${node_path.default.resolve(tsdk)}.`];
|
|
22654
|
+
if (found && is_usable_typescript(found.version)) {
|
|
22655
|
+
const from = found.source === "server" ? "the server installation" : "the project";
|
|
22656
|
+
sentences.push(`The server uses TypeScript ${found.version} from ${from} instead: ${found.dir}.`);
|
|
22657
|
+
}
|
|
22658
|
+
sentences.push("Set this option to the lib folder of a TypeScript installation, for example /path/to/node_modules/typescript/lib.");
|
|
22659
|
+
return sentences.join(" ");
|
|
22660
|
+
}
|
|
22638
22661
|
/**
|
|
22639
|
-
* The notice the server shows when it
|
|
22662
|
+
* The notice the server shows when it did not find a `typescript` it can run.
|
|
22640
22663
|
* @param {FoundTypeScript | undefined} found
|
|
22641
22664
|
* @param {readonly string[]} workspace_dirs
|
|
22642
22665
|
* @returns {string}
|
|
22643
22666
|
*/
|
|
22644
22667
|
function typescript_notice(found, workspace_dirs) {
|
|
22645
22668
|
if (found) return [
|
|
22646
|
-
`The TSRX language server found
|
|
22647
|
-
"
|
|
22669
|
+
`The TSRX language server found TypeScript ${found.version} in ${found.dir}.`,
|
|
22670
|
+
"The server cannot run TypeScript 7 or newer.",
|
|
22671
|
+
NO_FEATURES,
|
|
22648
22672
|
STILL_WORKS,
|
|
22649
|
-
"
|
|
22650
|
-
"
|
|
22673
|
+
"To use TypeScript 7, run the TypeScript 7 language server (tsc --lsp) with @tsrx/content-mapper.",
|
|
22674
|
+
"To use a different TypeScript, set the typescript.tsdk startup option to the lib folder of that TypeScript.",
|
|
22675
|
+
"For more information, see https://github.com/tsrx-org/tsrx/tree/main/packages/language-server#which-typescript-it-uses"
|
|
22651
22676
|
].join(" ");
|
|
22652
22677
|
return [
|
|
22653
|
-
`The TSRX language server
|
|
22654
|
-
|
|
22678
|
+
`The TSRX language server did not find TypeScript in ${workspace_dirs.join(", ")}, in the server installation, or in their parent folders.`,
|
|
22679
|
+
NO_FEATURES,
|
|
22655
22680
|
STILL_WORKS,
|
|
22656
|
-
"Install
|
|
22681
|
+
"Install TypeScript in the project: npm install -D typescript, or pnpm add -D typescript.",
|
|
22682
|
+
"Then restart the TSRX language server."
|
|
22657
22683
|
].join(" ");
|
|
22658
22684
|
}
|
|
22659
22685
|
|
|
@@ -22685,19 +22711,18 @@ const VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
22685
22711
|
]);
|
|
22686
22712
|
/**
|
|
22687
22713
|
* Auto-insert plugin for TSRX.
|
|
22688
|
-
* Handles auto-closing tags when typing '>' after a tag name
|
|
22714
|
+
* Handles auto-closing tags when typing '>' after a tag name. The VS Code extension
|
|
22715
|
+
* asks for them with Volar's `volar/client/autoInsert` request; other editors get
|
|
22716
|
+
* them through `textDocument/onTypeFormatting` (`closingTagsHandler.js`).
|
|
22689
22717
|
* @returns {LanguageServicePlugin}
|
|
22690
22718
|
*/
|
|
22691
22719
|
function createAutoInsertPlugin() {
|
|
22692
22720
|
return {
|
|
22693
22721
|
name: "tsrx-auto-insert",
|
|
22694
|
-
capabilities: {
|
|
22695
|
-
|
|
22696
|
-
|
|
22697
|
-
|
|
22698
|
-
},
|
|
22699
|
-
documentOnTypeFormattingProvider: { triggerCharacters: [">"] }
|
|
22700
|
-
},
|
|
22722
|
+
capabilities: { autoInsertionProvider: {
|
|
22723
|
+
triggerCharacters: [">"],
|
|
22724
|
+
configurationSections: ["tsrx.autoClosingTags.enabled"]
|
|
22725
|
+
} },
|
|
22701
22726
|
create(context) {
|
|
22702
22727
|
return {
|
|
22703
22728
|
/**
|
|
@@ -22766,12 +22791,30 @@ async provideAutoInsertSnippet(document, position, lastChange, _token) {
|
|
|
22766
22791
|
return null;
|
|
22767
22792
|
}
|
|
22768
22793
|
log$8("Inserting closing tag:", closingTag);
|
|
22769
|
-
return `$0${closingTag}`;
|
|
22794
|
+
return `$0${escapeSnippetText(closingTag)}`;
|
|
22770
22795
|
} };
|
|
22771
22796
|
}
|
|
22772
22797
|
};
|
|
22773
22798
|
}
|
|
22774
22799
|
/**
|
|
22800
|
+
* Escape `text` so that a snippet inserts it as written. `\`, `$` and `}` are snippet
|
|
22801
|
+
* syntax: unescaped, the `$Foo` in `</$Foo>` is a variable, which VS Code replaces
|
|
22802
|
+
* with nothing.
|
|
22803
|
+
* @param {string} text
|
|
22804
|
+
* @returns {string}
|
|
22805
|
+
*/
|
|
22806
|
+
function escapeSnippetText(text) {
|
|
22807
|
+
return text.replace(/[\\$}]/g, "\\$&");
|
|
22808
|
+
}
|
|
22809
|
+
/**
|
|
22810
|
+
* The text that a snippet made by `escapeSnippetText` inserts: `</\$Foo>` inserts `</$Foo>`.
|
|
22811
|
+
* @param {string} snippet
|
|
22812
|
+
* @returns {string}
|
|
22813
|
+
*/
|
|
22814
|
+
function unescapeSnippetText(snippet) {
|
|
22815
|
+
return snippet.replace(/\\([\\$}])/g, "$1");
|
|
22816
|
+
}
|
|
22817
|
+
/**
|
|
22775
22818
|
* Match an opening tag `<name …>` that ends exactly at the end of `text` and return its name.
|
|
22776
22819
|
*
|
|
22777
22820
|
* Attribute expressions may themselves contain `>` (`<style apply={x > y ? a : b}>`,
|
|
@@ -22781,11 +22824,14 @@ async provideAutoInsertSnippet(document, position, lastChange, _token) {
|
|
|
22781
22824
|
* expression, not closing the tag), an earlier `>` already closed the tag, or the tag is
|
|
22782
22825
|
* self-closing (`<style apply={theme} />`).
|
|
22783
22826
|
*
|
|
22827
|
+
* A name is made of JavaScript identifier characters, `.` and `-`, so `$` and non-ASCII
|
|
22828
|
+
* letters can appear anywhere in it (`<ui.$Item>`, `<Café>`).
|
|
22829
|
+
*
|
|
22784
22830
|
* @param {string} text - Source text from the tag's `<` up to and including the typed `>`
|
|
22785
22831
|
* @returns {string | null}
|
|
22786
22832
|
*/
|
|
22787
22833
|
function matchOpeningTag(text) {
|
|
22788
|
-
const nameMatch = text.match(/^<([
|
|
22834
|
+
const nameMatch = text.match(/^<([@$_\p{ID_Start}][$\p{ID_Continue}\u200C\u200D.-]*)/u);
|
|
22789
22835
|
if (!nameMatch) return null;
|
|
22790
22836
|
let depth = 0;
|
|
22791
22837
|
/** @type {string | null} */
|
|
@@ -24557,7 +24603,8 @@ function createTypeScriptServices(ts) {
|
|
|
24557
24603
|
/** @import { LanguageServicePlugin } from '@volar/language-server' */
|
|
24558
24604
|
/** @import { TypeScriptBackend } from './backend.js' */
|
|
24559
24605
|
/**
|
|
24560
|
-
* Strip
|
|
24606
|
+
* Strip the formatting capabilities from a Volar service plugin, on-type
|
|
24607
|
+
* formatting included.
|
|
24561
24608
|
*
|
|
24562
24609
|
* The bundled TypeScript (`typescript-syntactic`) and CSS services advertise a
|
|
24563
24610
|
* `documentFormattingProvider`. Because they run against the virtual TS/CSS code
|
|
@@ -24566,17 +24613,20 @@ function createTypeScriptServices(ts) {
|
|
|
24566
24613
|
* (`formattingHandler.js`): a plugin that offered formatting would make Volar
|
|
24567
24614
|
* register its own `textDocument/formatting` handler, which would replace that one,
|
|
24568
24615
|
* and the language client would list a second formatter that does nothing
|
|
24569
|
-
* (removed first by Ripple-TS/ripple#1318).
|
|
24570
|
-
*
|
|
24571
|
-
*
|
|
24572
|
-
*
|
|
24616
|
+
* (removed first by Ripple-TS/ripple#1318). TypeScript 7 registers a formatter for
|
|
24617
|
+
* `.tsrx` files that returns no edits (`native-lsp.test.js` pins it), so the VS Code
|
|
24618
|
+
* extension makes TSRX the `[tsrx]` default formatter.
|
|
24619
|
+
*
|
|
24620
|
+
* On-type formatting is the same: TypeScript's `;`, `}` and newline triggers
|
|
24621
|
+
* return nothing for `.tsrx` files (their mappings turn formatting off), and the
|
|
24622
|
+
* server answers `>` itself with the closing tag (`closingTagsHandler.js`).
|
|
24573
24623
|
*
|
|
24574
24624
|
* @template {{ capabilities?: Record<string, unknown> }} T
|
|
24575
24625
|
* @param {T} plugin
|
|
24576
24626
|
* @returns {T}
|
|
24577
24627
|
*/
|
|
24578
|
-
function
|
|
24579
|
-
const { documentFormattingProvider: _fmt, documentRangeFormattingProvider: _rangeFmt, ...capabilities } = plugin.capabilities ?? {};
|
|
24628
|
+
function stripFormatting(plugin) {
|
|
24629
|
+
const { documentFormattingProvider: _fmt, documentRangeFormattingProvider: _rangeFmt, documentOnTypeFormattingProvider: _onTypeFmt, ...capabilities } = plugin.capabilities ?? {};
|
|
24580
24630
|
return {
|
|
24581
24631
|
...plugin,
|
|
24582
24632
|
capabilities
|
|
@@ -24608,7 +24658,7 @@ function createServicePlugins(backend, ts) {
|
|
|
24608
24658
|
const shared_last = [
|
|
24609
24659
|
createDefinitionPlugin(),
|
|
24610
24660
|
createDocumentSymbolPlugin(),
|
|
24611
|
-
|
|
24661
|
+
stripFormatting((0, volar_service_css.create)())
|
|
24612
24662
|
];
|
|
24613
24663
|
if (backend === "native" || backend === "plugin") return [
|
|
24614
24664
|
...shared_first,
|
|
@@ -24622,7 +24672,7 @@ function createServicePlugins(backend, ts) {
|
|
|
24622
24672
|
...shared_first,
|
|
24623
24673
|
createCompileErrorDiagnosticPlugin(),
|
|
24624
24674
|
...shared_last,
|
|
24625
|
-
...createTypeScriptServices(ts).map(
|
|
24675
|
+
...createTypeScriptServices(ts).map(stripFormatting),
|
|
24626
24676
|
createTypeScriptDiagnosticFilterPlugin(),
|
|
24627
24677
|
createHoverPlugin({ typescriptBackend: backend }),
|
|
24628
24678
|
createDocumentHighlightPlugin({ typescriptBackend: backend })
|
|
@@ -24789,7 +24839,7 @@ function at_least(version, minimum) {
|
|
|
24789
24839
|
* Answer `textDocument/formatting` and `textDocument/rangeFormatting` (Format
|
|
24790
24840
|
* Selection, format on paste) for `.tsrx` files with `format_tsrx`, on the
|
|
24791
24841
|
* plain LSP connection: Volar only formats generated code, never the `.tsrx`
|
|
24792
|
-
* source, and its TypeScript and CSS formatters stay off (`
|
|
24842
|
+
* source, and its TypeScript and CSS formatters stay off (`stripFormatting`
|
|
24793
24843
|
* in `servicePlugins.js`), so this is the server's only formatter.
|
|
24794
24844
|
*
|
|
24795
24845
|
* When the project lacks `prettier` or `@tsrx/prettier-plugin`, or has a Prettier
|
|
@@ -24906,6 +24956,86 @@ async function formatting_enabled(connection, uri) {
|
|
|
24906
24956
|
}
|
|
24907
24957
|
}
|
|
24908
24958
|
|
|
24959
|
+
//#endregion
|
|
24960
|
+
//#region src/closingTagsHandler.js
|
|
24961
|
+
/** @import { Connection, DocumentOnTypeFormattingParams, InitializeParams, LanguageServer, ServerCapabilities, TextEdit } from '@volar/language-server' */
|
|
24962
|
+
/**
|
|
24963
|
+
* The on-type formatting the server offers: closing tags on `>`, and nothing else.
|
|
24964
|
+
* @type {NonNullable<ServerCapabilities['documentOnTypeFormattingProvider']>}
|
|
24965
|
+
*/
|
|
24966
|
+
const CLOSING_TAGS_ON_TYPE = { firstTriggerCharacter: ">" };
|
|
24967
|
+
/**
|
|
24968
|
+
* Whether the client gets its closing tags through `textDocument/onTypeFormatting`.
|
|
24969
|
+
* A client that closes tags another way sets the `closeTagsOnType` initialization
|
|
24970
|
+
* option to `false`: the VS Code extension, where VS Code's TypeScript closes them,
|
|
24971
|
+
* or the extension asks for them with Volar's `volar/client/autoInsert` request.
|
|
24972
|
+
* @param {InitializeParams} params
|
|
24973
|
+
*/
|
|
24974
|
+
function closes_tags_on_type(params) {
|
|
24975
|
+
return params.initializationOptions?.closeTagsOnType !== false;
|
|
24976
|
+
}
|
|
24977
|
+
/**
|
|
24978
|
+
* Close tags in every editor: answer `textDocument/onTypeFormatting` for `>` with
|
|
24979
|
+
* an edit that inserts the closing tag at the cursor. Only the VS Code extension
|
|
24980
|
+
* sends Volar's `volar/client/autoInsert` request. This handler asks the same
|
|
24981
|
+
* plugin (`provideAutoInsertSnippet` in `autoInsertPlugin.js`), drops the
|
|
24982
|
+
* snippet's `$0` and removes its escapes (`$0</\$Foo>` inserts `</$Foo>`). No
|
|
24983
|
+
* Volar service plugin offers on-type formatting (`stripFormatting` in
|
|
24984
|
+
* `servicePlugins.js`), so Volar registers no handler that would replace this one.
|
|
24985
|
+
*
|
|
24986
|
+
* A text edit cannot place the cursor. Editors that leave the cursor before text
|
|
24987
|
+
* inserted at the cursor (Zed 1.17 and newer, Neovim in Insert mode) keep it
|
|
24988
|
+
* between the tags. `tsrx.autoClosingTags.enabled: false` turns it off.
|
|
24989
|
+
* @param {Connection} connection
|
|
24990
|
+
* @param {LanguageServer} server
|
|
24991
|
+
*/
|
|
24992
|
+
function register_closing_tags(connection, server) {
|
|
24993
|
+
connection.onDocumentOnTypeFormatting(
|
|
24994
|
+
/**
|
|
24995
|
+
* @param {DocumentOnTypeFormattingParams} params
|
|
24996
|
+
* @returns {Promise<TextEdit[] | null>}
|
|
24997
|
+
*/
|
|
24998
|
+
async (params, token) => {
|
|
24999
|
+
if (params.ch !== ">" || !is_tsrx_document(params.textDocument.uri)) return null;
|
|
25000
|
+
const uri = vscode_uri.URI.parse(params.textDocument.uri);
|
|
25001
|
+
const document = server.documents.get(uri);
|
|
25002
|
+
if (!document) return null;
|
|
25003
|
+
const offset = document.offsetAt(params.position);
|
|
25004
|
+
if (document.getText().charAt(offset - 1) !== ">") return null;
|
|
25005
|
+
if (!await closing_tags_enabled(connection, params.textDocument.uri)) return null;
|
|
25006
|
+
const snippet = await (await server.project.getLanguageService(uri)).getAutoInsertSnippet(uri, params.position, {
|
|
25007
|
+
rangeOffset: offset - 1,
|
|
25008
|
+
rangeLength: 0,
|
|
25009
|
+
text: ">"
|
|
25010
|
+
}, token);
|
|
25011
|
+
if (token.isCancellationRequested || !snippet?.startsWith("$0")) return null;
|
|
25012
|
+
return [{
|
|
25013
|
+
range: {
|
|
25014
|
+
start: params.position,
|
|
25015
|
+
end: params.position
|
|
25016
|
+
},
|
|
25017
|
+
newText: unescapeSnippetText(snippet.slice(2))
|
|
25018
|
+
}];
|
|
25019
|
+
}
|
|
25020
|
+
);
|
|
25021
|
+
}
|
|
25022
|
+
/**
|
|
25023
|
+
* `tsrx.autoClosingTags.enabled`, which defaults to true. A client that does not
|
|
25024
|
+
* answer `workspace/configuration` leaves closing tags on.
|
|
25025
|
+
* @param {Connection} connection
|
|
25026
|
+
* @param {string} uri
|
|
25027
|
+
*/
|
|
25028
|
+
async function closing_tags_enabled(connection, uri) {
|
|
25029
|
+
try {
|
|
25030
|
+
return await connection.workspace.getConfiguration({
|
|
25031
|
+
scopeUri: uri,
|
|
25032
|
+
section: "tsrx.autoClosingTags.enabled"
|
|
25033
|
+
}) !== false;
|
|
25034
|
+
} catch {
|
|
25035
|
+
return true;
|
|
25036
|
+
}
|
|
25037
|
+
}
|
|
25038
|
+
|
|
24909
25039
|
//#endregion
|
|
24910
25040
|
//#region src/workspaceState.js
|
|
24911
25041
|
const WORKSPACE_FILE_PATTERNS = [
|
|
@@ -25060,6 +25190,7 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25060
25190
|
const connection = (0, import_node.createConnection)();
|
|
25061
25191
|
const server = (0, import_node.createServer)(connection);
|
|
25062
25192
|
register_formatting(connection, (uri) => server.documents.get(vscode_uri.URI.parse(uri)));
|
|
25193
|
+
register_closing_tags(connection, server);
|
|
25063
25194
|
connection.listen();
|
|
25064
25195
|
/** @type {WeakSet<Function>} */
|
|
25065
25196
|
const wrappedFunctions = /* @__PURE__ */ new WeakSet();
|
|
@@ -25070,11 +25201,12 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25070
25201
|
let restartScheduled = false;
|
|
25071
25202
|
let clientRestarts = false;
|
|
25072
25203
|
/**
|
|
25073
|
-
* Shown once the client is initialized,
|
|
25074
|
-
* `typescript`
|
|
25075
|
-
*
|
|
25204
|
+
* Shown once the client is initialized, each as its own warning: the classic
|
|
25205
|
+
* backend skipped the `typescript.tsdk` option, or did not find a `typescript`
|
|
25206
|
+
* it can run and the server started without TypeScript features.
|
|
25207
|
+
* @type {string[]}
|
|
25076
25208
|
*/
|
|
25077
|
-
|
|
25209
|
+
const typescriptNotices = [];
|
|
25078
25210
|
/**
|
|
25079
25211
|
* Restart the process so Node drops the complete ESM compiler graph. A
|
|
25080
25212
|
* client that restarts the server itself stops sending first. When the
|
|
@@ -25154,17 +25286,19 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25154
25286
|
let ts;
|
|
25155
25287
|
if (backend === "classic") {
|
|
25156
25288
|
const workspace_dirs = workspace_folder_paths(params);
|
|
25289
|
+
const tsdk = resolve_typescript_tsdk(params.initializationOptions);
|
|
25157
25290
|
const found = find_typescript({
|
|
25158
|
-
tsdk
|
|
25291
|
+
tsdk,
|
|
25159
25292
|
workspace_dirs,
|
|
25160
25293
|
server_dir: SERVER_DIR
|
|
25161
25294
|
});
|
|
25295
|
+
if (tsdk !== void 0 && found?.source !== "tsdk") typescriptNotices.push(tsdk_notice(tsdk, found));
|
|
25162
25296
|
if (found && is_usable_typescript(found.version)) ts = load_typescript(found);
|
|
25163
25297
|
else {
|
|
25164
|
-
|
|
25165
|
-
logError(typescriptNotice);
|
|
25298
|
+
typescriptNotices.push(typescript_notice(found, workspace_dirs));
|
|
25166
25299
|
backend = "plugin";
|
|
25167
25300
|
}
|
|
25301
|
+
for (const notice of typescriptNotices) logError(notice);
|
|
25168
25302
|
}
|
|
25169
25303
|
if (ts === void 0) {
|
|
25170
25304
|
const compilerResolutionDependencies = /* @__PURE__ */ new Set();
|
|
@@ -25175,7 +25309,7 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25175
25309
|
});
|
|
25176
25310
|
const initResult = server.initialize(params, (0, import_node.createSimpleProject)([languagePlugin]), createServicePlugins(backend));
|
|
25177
25311
|
log("Server initialization complete");
|
|
25178
|
-
return
|
|
25312
|
+
return with_own_handlers(initResult, params);
|
|
25179
25313
|
}
|
|
25180
25314
|
const initResult = server.initialize(params, (0, import_node.createTypeScriptProject)(ts, void 0, ({ configFileName, projectHost, sys }) => {
|
|
25181
25315
|
wrapCompilerOptionsProvider(projectHost, "getCompilationSettings");
|
|
@@ -25200,7 +25334,7 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25200
25334
|
};
|
|
25201
25335
|
}), createServicePlugins(backend, ts));
|
|
25202
25336
|
log("Server initialization complete");
|
|
25203
|
-
return
|
|
25337
|
+
return with_own_handlers(initResult, params);
|
|
25204
25338
|
} catch (initError) {
|
|
25205
25339
|
logError("Server initialization failed:", initError);
|
|
25206
25340
|
throw initError;
|
|
@@ -25209,9 +25343,9 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25209
25343
|
connection.onInitialized(async () => {
|
|
25210
25344
|
log("Server initialized.");
|
|
25211
25345
|
server.initialized();
|
|
25212
|
-
|
|
25346
|
+
for (const message of typescriptNotices) connection.sendNotification("window/showMessage", {
|
|
25213
25347
|
type: 2,
|
|
25214
|
-
message
|
|
25348
|
+
message
|
|
25215
25349
|
});
|
|
25216
25350
|
server.fileWatcher.onDidChangeWatchedFiles(({ changes }) => {
|
|
25217
25351
|
for (const configDependencies of compilerResolutionDependencySets) trackTypeScriptConfigDependencies(trackedTypeScriptConfigFiles, { configDependencies });
|
|
@@ -25244,15 +25378,19 @@ function createTsrxLanguageServer(options = {}) {
|
|
|
25244
25378
|
};
|
|
25245
25379
|
}
|
|
25246
25380
|
/**
|
|
25247
|
-
* Advertise the
|
|
25248
|
-
*
|
|
25381
|
+
* Advertise what the server's own handlers serve: the formatters `register_formatting`
|
|
25382
|
+
* serves (whole document and range), and the closing tags `register_closing_tags`
|
|
25383
|
+
* serves on `>`, unless the client closes tags another way (`closes_tags_on_type`).
|
|
25384
|
+
* No Volar service plugin advertises either (`stripFormatting`).
|
|
25249
25385
|
* @template {import('@volar/language-server/node').InitializeResult} T
|
|
25250
25386
|
* @param {T} initResult
|
|
25387
|
+
* @param {import('@volar/language-server/node').InitializeParams} params
|
|
25251
25388
|
* @returns {T}
|
|
25252
25389
|
*/
|
|
25253
|
-
function
|
|
25390
|
+
function with_own_handlers(initResult, params) {
|
|
25254
25391
|
initResult.capabilities.documentFormattingProvider = true;
|
|
25255
25392
|
initResult.capabilities.documentRangeFormattingProvider = true;
|
|
25393
|
+
if (closes_tags_on_type(params)) initResult.capabilities.documentOnTypeFormattingProvider = CLOSING_TAGS_ON_TYPE;
|
|
25256
25394
|
return initResult;
|
|
25257
25395
|
}
|
|
25258
25396
|
/**
|
|
@@ -25289,4 +25427,4 @@ Object.defineProperty(exports, 'createTsrxLanguageServer', {
|
|
|
25289
25427
|
return createTsrxLanguageServer;
|
|
25290
25428
|
}
|
|
25291
25429
|
});
|
|
25292
|
-
//# sourceMappingURL=server-
|
|
25430
|
+
//# sourceMappingURL=server-y1HvqjeS.js.map
|