@adecore/lsp 0.62.1 → 0.63.0

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.
@@ -1,5 +1,4 @@
1
1
  import { asError } from './as-error.js';
2
- /* The JSON-RPC and LSP codes this package answers with. */
3
2
  export const ErrorCodes = {
4
3
  InvalidRequest: -32600,
5
4
  MethodNotFound: -32601,
@@ -30,7 +29,6 @@ export class StaleResultError extends LspError {
30
29
  function cancelledError() {
31
30
  return new LspError('Request cancelled', ErrorCodes.RequestCancelled);
32
31
  }
33
- /* JSON-RPC 2.0 over an `LspTransport`: correlation, cancellation, and the requests a server sends back. */
34
32
  export class JsonRpcConnection {
35
33
  transport;
36
34
  timeoutMs;
@@ -94,7 +92,6 @@ export class JsonRpcConnection {
94
92
  void this.send({ jsonrpc: '2.0', id, method, params: progress.params }).catch((error) => this.settle(id, undefined, error));
95
93
  });
96
94
  }
97
- /* Adds the tokens of partial results and work-done progress to the params of a request, and hears `$/progress` for them. */
98
95
  progressOf(id, params, options) {
99
96
  const { onPartialResult, onWorkDoneProgress } = options;
100
97
  if ((onPartialResult === undefined && onWorkDoneProgress === undefined) || params === null || typeof params !== 'object' || Array.isArray(params)) {
@@ -1,7 +1,18 @@
1
- import type { CallHierarchyIncomingCall, CallHierarchyItem, CallHierarchyOutgoingCall, CodeAction, CodeActionContext, CodeLens, Color, ColorInformation, ColorPresentation, Command, CompletionContext, CompletionItem, CompletionResult, ContentChange, DocumentDiagnosticReport, DocumentHighlight, DocumentItem, DocumentLink, DocumentRequestOptions, DocumentSymbolResult, FoldingRange, FormattingOptions, Hover, InlayHint, InlineCompletionContext, InlineCompletionResult, InlineValue, InlineValueContext, LinkedEditingRanges, Location, Moniker, NavigationResult, Position, PrepareRenameResult, Range, SelectionRange, SemanticTokens, SemanticTokensDelta, SignatureHelp, SignatureHelpContext, TextDocumentSaveReason, TextEdit, TypeHierarchyItem, WorkspaceEdit } from './protocol.ts';
2
- import type { LspSession } from './session.ts';
1
+ import { type JsonRpcConnection } from './connection.ts';
2
+ import type { CallHierarchyIncomingCall, CallHierarchyItem, CallHierarchyOutgoingCall, CodeAction, CodeActionContext, CodeLens, Color, ColorInformation, ColorPresentation, Command, CompletionContext, CompletionItem, CompletionResult, ContentChange, DocumentDiagnosticReport, DocumentHighlight, DocumentItem, DocumentLink, DocumentRequestOptions, DocumentSymbolResult, FoldingRange, FormattingOptions, Hover, InlayHint, InlineCompletionContext, InlineCompletionResult, InlineValue, InlineValueContext, LinkedEditingRanges, Location, Moniker, NavigationResult, Position, PrepareRenameResult, Range, RequestOptions, SelectionRange, SemanticTokens, SemanticTokensDelta, SignatureHelp, SignatureHelpContext, TextDocumentSaveReason, TextDocumentSyncOptions, TextEdit, TypeHierarchyItem, WorkspaceEdit } from './protocol.ts';
3
+ interface DocumentSession {
4
+ readonly connection: JsonRpcConnection;
5
+ readonly options: {
6
+ readonly fullSyncDelayMs?: number;
7
+ };
8
+ readonly syncOptions: TextDocumentSyncOptions;
9
+ supports(method: string, document?: Pick<DocumentItem, 'uri' | 'languageId'>): boolean;
10
+ request<T = unknown>(method: string, params?: unknown, options?: RequestOptions): Promise<T>;
11
+ notify(method: string, params?: unknown): Promise<void>;
12
+ forgetDocument(document: LspDocument): void;
13
+ }
3
14
  export declare class LspDocument {
4
- readonly session: LspSession;
15
+ readonly session: DocumentSession;
5
16
  readonly uri: string;
6
17
  readonly languageId: string;
7
18
  readonly ready: Promise<void>;
@@ -14,7 +25,7 @@ export declare class LspDocument {
14
25
  private readonly inFlight;
15
26
  private readonly latest;
16
27
  private readonly resultVersions;
17
- constructor(session: LspSession, item: DocumentItem);
28
+ constructor(session: DocumentSession, item: DocumentItem);
18
29
  get version(): number;
19
30
  get text(): string;
20
31
  get isClosed(): boolean;
@@ -78,3 +89,4 @@ export declare class LspDocument {
78
89
  private queueFullText;
79
90
  private cancelRequests;
80
91
  }
92
+ export {};
package/dist/document.js CHANGED
@@ -232,7 +232,6 @@ export class LspDocument {
232
232
  rangesFormatting(ranges, formatting, options) {
233
233
  return this.feature('textDocument/rangesFormatting', { ranges: [...ranges], options: formatting }, options);
234
234
  }
235
- /* Tells the server a save is coming, when it asked to hear it. */
236
235
  async willSave(reason = 1) {
237
236
  this.assertOpen();
238
237
  if (this.session.syncOptions.willSave) {
package/dist/edits.js CHANGED
@@ -65,7 +65,6 @@ export function positionAt(text, offset) {
65
65
  }
66
66
  return { line, character: offset - lineStart };
67
67
  }
68
- /* The position after the last character. */
69
68
  export function endPosition(text) {
70
69
  return positionAt(text, text.length);
71
70
  }
@@ -187,7 +186,6 @@ function planCreate(change, snapshots, planned) {
187
186
  throw new LspError(`${change.uri} already exists`);
188
187
  }
189
188
  }
190
- /* The changes of an edit in order, with the older `changes` map read as unversioned text edits. */
191
189
  export function documentChangesOf(edit) {
192
190
  return edit.documentChanges ?? Object.entries(edit.changes ?? {}).map(([uri, edits]) => ({ textDocument: { uri, version: null }, edits }));
193
191
  }
@@ -24,7 +24,6 @@ function anyTakes(filters, uri, directory) {
24
24
  export function renamesTaken(filters, files) {
25
25
  return files.filter((file) => anyTakes(filters, file.oldUri, file.directory)).map(({ oldUri, newUri }) => ({ oldUri, newUri }));
26
26
  }
27
- /* The files made that a server asked to hear about, by the filters it registered. */
28
27
  export function createsTaken(filters, files) {
29
28
  return files.filter((file) => anyTakes(filters, file.uri, file.directory)).map(({ uri }) => ({ uri }));
30
29
  }
package/dist/index.d.ts CHANGED
@@ -11,5 +11,6 @@ export type { DiagnosticsReport, LanguageDocument, LanguageRequestOptions, Langu
11
11
  export { unservedLanguageService } from './unserved.ts';
12
12
  export { connectWebSocket, createStreamTransport, type ByteStream, type WebSocketTransportOptions } from './transport.ts';
13
13
  export { fileUriToPath, pathToFileUri } from './uris.ts';
14
+ export { documentLanguageId, lspLanguageId, lspLanguageIdOf, SCRIPT_LANGUAGE_IDS } from './language-ids.ts';
14
15
  export { bridgeVueTypeScript, vueServerOrder, type VueServer } from './vue.ts';
15
16
  export type * from './protocol.ts';
package/dist/index.js CHANGED
@@ -10,4 +10,5 @@ export { TextMirror } from './text-mirror.js';
10
10
  export { unservedLanguageService } from './unserved.js';
11
11
  export { connectWebSocket, createStreamTransport } from './transport.js';
12
12
  export { fileUriToPath, pathToFileUri } from './uris.js';
13
+ export { documentLanguageId, lspLanguageId, lspLanguageIdOf, SCRIPT_LANGUAGE_IDS } from './language-ids.js';
13
14
  export { bridgeVueTypeScript, vueServerOrder } from './vue.js';
@@ -0,0 +1,4 @@
1
+ export declare const SCRIPT_LANGUAGE_IDS: readonly ['typescript', 'typescriptreact', 'javascript', 'javascriptreact'];
2
+ export declare function lspLanguageIdOf(language: string | undefined): string | null;
3
+ export declare function lspLanguageId(language: string): string;
4
+ export declare function documentLanguageId(language: string, path: string): string;
@@ -0,0 +1,54 @@
1
+ export const SCRIPT_LANGUAGE_IDS = ['typescript', 'typescriptreact', 'javascript', 'javascriptreact'];
2
+ const LSP_IDS = {
3
+ typescript: 'typescript',
4
+ ts: 'typescript',
5
+ mts: 'typescript',
6
+ cts: 'typescript',
7
+ tsx: 'typescriptreact',
8
+ javascript: 'javascript',
9
+ js: 'javascript',
10
+ mjs: 'javascript',
11
+ cjs: 'javascript',
12
+ jsx: 'javascriptreact',
13
+ vue: 'vue',
14
+ php: 'php',
15
+ css: 'css',
16
+ scss: 'scss',
17
+ less: 'less',
18
+ html: 'html',
19
+ json: 'json',
20
+ jsonc: 'jsonc',
21
+ yaml: 'yaml',
22
+ yml: 'yaml',
23
+ python: 'python',
24
+ py: 'python',
25
+ shellscript: 'shellscript',
26
+ sh: 'shellscript',
27
+ bash: 'shellscript',
28
+ zsh: 'shellscript',
29
+ docker: 'dockerfile',
30
+ twig: 'twig',
31
+ sql: 'sql',
32
+ rust: 'rust',
33
+ markdown: 'markdown',
34
+ toml: 'toml',
35
+ lua: 'lua',
36
+ go: 'go',
37
+ swift: 'swift',
38
+ zig: 'zig'
39
+ };
40
+ /* The LSP id of a language, or null when no language server here knows it. */
41
+ export function lspLanguageIdOf(language) {
42
+ return language === undefined ? null : (LSP_IDS[language] ?? null);
43
+ }
44
+ /* The LSP id for a name a client may use, which is the name itself for a language the table does not list. */
45
+ export function lspLanguageId(language) {
46
+ return LSP_IDS[language] ?? language;
47
+ }
48
+ /* Files that are JSON with comments and trailing commas: a JSON server reports both as errors in a plain `json` document. */
49
+ const JSONC_FILES = /(^|\/)(tsconfig(\..+)?\.json|jsconfig(\..+)?\.json|\.eslintrc(\.json)?|\.babelrc(\.json)?|\.swcrc|devcontainer\.json|\.devcontainer\/.+\.json|\.vscode\/.+\.json|.+\.jsonc)$/;
50
+ /* The language id a document opens with: the LSP id of the language, except for a JSON file that allows comments. */
51
+ export function documentLanguageId(language, path) {
52
+ const id = lspLanguageId(language);
53
+ return id === 'json' && JSONC_FILES.test(path) ? 'jsonc' : id;
54
+ }
package/dist/session.js CHANGED
@@ -3,7 +3,6 @@ import { LspDocument } from './document.js';
3
3
  import { createsTaken, deletesTaken, renamesTaken } from './file-operations.js';
4
4
  import { globMatch } from './glob.js';
5
5
  import { fileUriKey } from './uris.js';
6
- /* The capability that advertises each method statically. */
7
6
  const PROVIDERS = {
8
7
  'textDocument/completion': 'completionProvider',
9
8
  'completionItem/resolve': 'completionProvider',
@@ -94,7 +93,6 @@ function matches(options, document) {
94
93
  (!filter.scheme || filter.scheme === url.protocol.slice(0, -1)) &&
95
94
  (!filter.pattern || globMatch(decodeURIComponent(url.pathname), filter.pattern)));
96
95
  }
97
- /* Whether provider options cover a method that a provider only offers on top of its feature. */
98
96
  function offersMethod(method, options) {
99
97
  if (method.endsWith('/resolve')) {
100
98
  return options.resolveProvider === true;
@@ -119,7 +117,6 @@ function offersMethod(method, options) {
119
117
  }
120
118
  return true;
121
119
  }
122
- /* One conversation with one language server: the handshake, what it can do, and the documents open in it. */
123
120
  export class LspSession {
124
121
  connection;
125
122
  options;
@@ -328,11 +325,9 @@ export class LspSession {
328
325
  }
329
326
  return this.request('workspace/textDocumentContent', { uri }, options);
330
327
  }
331
- /* Changes the trace level the server sends `$/logTrace` at. */
332
328
  setTrace(value) {
333
329
  return this.notify('$/setTrace', { value });
334
330
  }
335
- /* Asks the server to stop work it reported as cancellable under `token`. */
336
331
  cancelWorkDoneProgress(token) {
337
332
  return this.notify('window/workDoneProgress/cancel', { token });
338
333
  }
@@ -452,7 +447,6 @@ export class LspSession {
452
447
  async willRenameFiles(files, options) {
453
448
  return this.askBefore('willRename', renamesTaken(this.fileOperationFilters('willRename'), files), options);
454
449
  }
455
- /* Tells the server which of these files moved, those its filters take. */
456
450
  async didRenameFiles(files) {
457
451
  await this.tellAfter('didRename', renamesTaken(this.fileOperationFilters('didRename'), files));
458
452
  }
@@ -460,7 +454,6 @@ export class LspSession {
460
454
  async willCreateFiles(files, options) {
461
455
  return this.askBefore('willCreate', createsTaken(this.fileOperationFilters('willCreate'), files), options);
462
456
  }
463
- /* Tells the server which of these files were made, those its filters take. */
464
457
  async didCreateFiles(files) {
465
458
  await this.tellAfter('didCreate', createsTaken(this.fileOperationFilters('didCreate'), files));
466
459
  }
@@ -468,7 +461,6 @@ export class LspSession {
468
461
  async willDeleteFiles(files, options) {
469
462
  return this.askBefore('willDelete', deletesTaken(this.fileOperationFilters('willDelete'), files), options);
470
463
  }
471
- /* Tells the server which of these files were deleted, those its filters take. */
472
464
  async didDeleteFiles(files) {
473
465
  await this.tellAfter('didDelete', deletesTaken(this.fileOperationFilters('didDelete'), files));
474
466
  }
@@ -40,7 +40,6 @@ export class ScriptedTransport {
40
40
  listener(message);
41
41
  }
42
42
  }
43
- /* The last request of `method` the client sent. */
44
43
  request(method) {
45
44
  return this.sent.findLast((message) => 'method' in message && message.method === method && 'id' in message);
46
45
  }
package/dist/testing.js CHANGED
@@ -52,7 +52,6 @@ export class FakeLanguageServer {
52
52
  handle(method, handler) {
53
53
  this.connection.onRequest(method, handler);
54
54
  }
55
- /* The params of every request or notification of `method`, in the order they came. */
56
55
  paramsOf(method) {
57
56
  return this.received.filter((message) => message.method === method).map((message) => message.params);
58
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/lsp",
3
- "version": "0.62.1",
3
+ "version": "0.63.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,7 @@
20
20
  "test": "bun test --conditions=source"
21
21
  },
22
22
  "dependencies": {
23
- "@adecore/utils": "0.62.1"
23
+ "@adecore/utils": "0.63.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/bun": "^1.4.4",
package/src/connection.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { asError } from './as-error.ts';
2
2
  import type { Disposable, LspTransport, RequestId, RequestOptions, RpcMessage, RpcRequest, WorkDoneProgress } from './protocol.ts';
3
3
 
4
- /* The JSON-RPC and LSP codes this package answers with. */
5
4
  export const ErrorCodes = {
6
5
  InvalidRequest: -32600,
7
6
  MethodNotFound: -32601,
@@ -47,7 +46,6 @@ function cancelledError(): LspError {
47
46
  return new LspError('Request cancelled', ErrorCodes.RequestCancelled);
48
47
  }
49
48
 
50
- /* JSON-RPC 2.0 over an `LspTransport`: correlation, cancellation, and the requests a server sends back. */
51
49
  export class JsonRpcConnection {
52
50
  readonly transport: LspTransport;
53
51
  readonly timeoutMs: number;
@@ -125,7 +123,6 @@ export class JsonRpcConnection {
125
123
  });
126
124
  }
127
125
 
128
- /* Adds the tokens of partial results and work-done progress to the params of a request, and hears `$/progress` for them. */
129
126
  private progressOf(id: RequestId, params: unknown, options: RequestOptions): { params: unknown; listening?: Disposable } {
130
127
  const { onPartialResult, onWorkDoneProgress } = options;
131
128
  if ((onPartialResult === undefined && onWorkDoneProgress === undefined) || params === null || typeof params !== 'object' || Array.isArray(params)) {
package/src/document.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ErrorCodes, LspError, StaleResultError } from './connection.ts';
1
+ import { ErrorCodes, LspError, StaleResultError, type JsonRpcConnection } from './connection.ts';
2
2
  import { minimalChange } from './edits.ts';
3
3
  import type {
4
4
  CallHierarchyIncomingCall,
@@ -36,29 +36,40 @@ import type {
36
36
  Position,
37
37
  PrepareRenameResult,
38
38
  Range,
39
+ RequestOptions,
39
40
  SelectionRange,
40
41
  SemanticTokens,
41
42
  SemanticTokensDelta,
42
43
  SignatureHelp,
43
44
  SignatureHelpContext,
44
45
  TextDocumentSaveReason,
46
+ TextDocumentSyncOptions,
45
47
  TextEdit,
46
48
  TypeHierarchyItem,
47
49
  WorkspaceEdit
48
50
  } from './protocol.ts';
49
- import type { LspSession } from './session.ts';
50
51
  import { TextMirror } from './text-mirror.ts';
51
52
 
52
53
  /* The delay of the VS Code language client for servers with full sync. */
53
54
  const FULL_SYNC_DELAY_MS = 200;
54
55
 
56
+ interface DocumentSession {
57
+ readonly connection: JsonRpcConnection;
58
+ readonly options: { readonly fullSyncDelayMs?: number };
59
+ readonly syncOptions: TextDocumentSyncOptions;
60
+ supports(method: string, document?: Pick<DocumentItem, 'uri' | 'languageId'>): boolean;
61
+ request<T = unknown>(method: string, params?: unknown, options?: RequestOptions): Promise<T>;
62
+ notify(method: string, params?: unknown): Promise<void>;
63
+ forgetDocument(document: LspDocument): void;
64
+ }
65
+
55
66
  /*
56
67
  * One open text document in one session. It owns the version, which every change raises by one. It
57
68
  * refuses a result that arrives for an older version, so nothing computed for a text that is gone
58
69
  * reaches the caller.
59
70
  */
60
71
  export class LspDocument {
61
- readonly session: LspSession;
72
+ readonly session: DocumentSession;
62
73
  readonly uri: string;
63
74
  readonly languageId: string;
64
75
  readonly ready: Promise<void>;
@@ -72,7 +83,7 @@ export class LspDocument {
72
83
  private readonly latest = new Map<string, AbortController>();
73
84
  private readonly resultVersions = new WeakMap<object, number>();
74
85
 
75
- constructor(session: LspSession, item: DocumentItem) {
86
+ constructor(session: DocumentSession, item: DocumentItem) {
76
87
  // A uri that does not parse is the caller's bug, and fails here instead of inside a server.
77
88
  new URL(item.uri);
78
89
  this.session = session;
@@ -347,7 +358,6 @@ export class LspDocument {
347
358
  return this.feature('textDocument/rangesFormatting', { ranges: [...ranges], options: formatting }, options);
348
359
  }
349
360
 
350
- /* Tells the server a save is coming, when it asked to hear it. */
351
361
  async willSave(reason: TextDocumentSaveReason = 1): Promise<void> {
352
362
  this.assertOpen();
353
363
  if (this.session.syncOptions.willSave) {
package/src/edits.ts CHANGED
@@ -95,7 +95,6 @@ export function positionAt(text: string, offset: number): Position {
95
95
  return { line, character: offset - lineStart };
96
96
  }
97
97
 
98
- /* The position after the last character. */
99
98
  export function endPosition(text: string): Position {
100
99
  return positionAt(text, text.length);
101
100
  }
@@ -228,7 +227,6 @@ export function minimalChange(before: string, after: string): ContentChange {
228
227
  };
229
228
  }
230
229
 
231
- // The snapshots by `fileUriKey`, each with the URI it was given under, which the plan keeps.
232
230
  type KeyedSnapshots = ReadonlyMap<string, { uri: string; snapshot: DocumentSnapshot }>;
233
231
 
234
232
  function snapshotEdit(uri: string, snapshots: KeyedSnapshots): PlannedDocumentEdit {
@@ -255,7 +253,6 @@ function planCreate(change: CreateFile, snapshots: KeyedSnapshots, planned: Map<
255
253
  }
256
254
  }
257
255
 
258
- /* The changes of an edit in order, with the older `changes` map read as unversioned text edits. */
259
256
  export function documentChangesOf(edit: WorkspaceEdit): NonNullable<WorkspaceEdit['documentChanges']> {
260
257
  return edit.documentChanges ?? Object.entries(edit.changes ?? {}).map(([uri, edits]) => ({ textDocument: { uri, version: null }, edits }));
261
258
  }
@@ -6,12 +6,10 @@ export interface RenamedFile extends FileRename {
6
6
  directory: boolean;
7
7
  }
8
8
 
9
- /* A file or folder that is made. */
10
9
  export interface CreatedFile extends FileCreate {
11
10
  directory: boolean;
12
11
  }
13
12
 
14
- /* A file or folder that is deleted. */
15
13
  export interface DeletedFile extends FileDelete {
16
14
  directory: boolean;
17
15
  }
@@ -49,7 +47,6 @@ export function renamesTaken(filters: readonly FileOperationFilter[], files: rea
49
47
  return files.filter((file) => anyTakes(filters, file.oldUri, file.directory)).map(({ oldUri, newUri }) => ({ oldUri, newUri }));
50
48
  }
51
49
 
52
- /* The files made that a server asked to hear about, by the filters it registered. */
53
50
  export function createsTaken(filters: readonly FileOperationFilter[], files: readonly CreatedFile[]): FileCreate[] {
54
51
  return files.filter((file) => anyTakes(filters, file.uri, file.directory)).map(({ uri }) => ({ uri }));
55
52
  }
package/src/index.ts CHANGED
@@ -22,5 +22,6 @@ export type { DiagnosticsReport, LanguageDocument, LanguageRequestOptions, Langu
22
22
  export { unservedLanguageService } from './unserved.ts';
23
23
  export { connectWebSocket, createStreamTransport, type ByteStream, type WebSocketTransportOptions } from './transport.ts';
24
24
  export { fileUriToPath, pathToFileUri } from './uris.ts';
25
+ export { documentLanguageId, lspLanguageId, lspLanguageIdOf, SCRIPT_LANGUAGE_IDS } from './language-ids.ts';
25
26
  export { bridgeVueTypeScript, vueServerOrder, type VueServer } from './vue.ts';
26
27
  export type * from './protocol.ts';
@@ -0,0 +1,61 @@
1
+ export const SCRIPT_LANGUAGE_IDS = ['typescript', 'typescriptreact', 'javascript', 'javascriptreact'] as const;
2
+
3
+ const LSP_IDS: Readonly<Record<string, string>> = {
4
+ typescript: 'typescript',
5
+ ts: 'typescript',
6
+ mts: 'typescript',
7
+ cts: 'typescript',
8
+ tsx: 'typescriptreact',
9
+ javascript: 'javascript',
10
+ js: 'javascript',
11
+ mjs: 'javascript',
12
+ cjs: 'javascript',
13
+ jsx: 'javascriptreact',
14
+ vue: 'vue',
15
+ php: 'php',
16
+ css: 'css',
17
+ scss: 'scss',
18
+ less: 'less',
19
+ html: 'html',
20
+ json: 'json',
21
+ jsonc: 'jsonc',
22
+ yaml: 'yaml',
23
+ yml: 'yaml',
24
+ python: 'python',
25
+ py: 'python',
26
+ shellscript: 'shellscript',
27
+ sh: 'shellscript',
28
+ bash: 'shellscript',
29
+ zsh: 'shellscript',
30
+ docker: 'dockerfile',
31
+ twig: 'twig',
32
+ sql: 'sql',
33
+ rust: 'rust',
34
+ markdown: 'markdown',
35
+ toml: 'toml',
36
+ lua: 'lua',
37
+ go: 'go',
38
+ swift: 'swift',
39
+ zig: 'zig'
40
+ };
41
+
42
+ /* The LSP id of a language, or null when no language server here knows it. */
43
+ export function lspLanguageIdOf(language: string | undefined): string | null {
44
+ return language === undefined ? null : (LSP_IDS[language] ?? null);
45
+ }
46
+
47
+ /* The LSP id for a name a client may use, which is the name itself for a language the table does not list. */
48
+ export function lspLanguageId(language: string): string {
49
+ return LSP_IDS[language] ?? language;
50
+ }
51
+
52
+ /* Files that are JSON with comments and trailing commas: a JSON server reports both as errors in a plain `json` document. */
53
+ const JSONC_FILES =
54
+ /(^|\/)(tsconfig(\..+)?\.json|jsconfig(\..+)?\.json|\.eslintrc(\.json)?|\.babelrc(\.json)?|\.swcrc|devcontainer\.json|\.devcontainer\/.+\.json|\.vscode\/.+\.json|.+\.jsonc)$/;
55
+
56
+ /* The language id a document opens with: the LSP id of the language, except for a JSON file that allows comments. */
57
+ export function documentLanguageId(language: string, path: string): string {
58
+ const id = lspLanguageId(language);
59
+
60
+ return id === 'json' && JSONC_FILES.test(path) ? 'jsonc' : id;
61
+ }
package/src/protocol.ts CHANGED
@@ -455,7 +455,6 @@ export interface ProviderOptions {
455
455
  watchers?: FileSystemWatcher[];
456
456
  codeActionKinds?: string[];
457
457
  legend?: SemanticTokensLegend;
458
- /* Of a file operation registration. */
459
458
  filters?: FileOperationFilter[];
460
459
  range?: boolean | object;
461
460
  full?: boolean | { delta?: boolean };
package/src/service.ts CHANGED
@@ -176,7 +176,6 @@ export interface LanguageService {
176
176
  onShowDocument?(handler: (params: ShowDocumentParams) => Promise<ShowDocumentResult>): Disposable;
177
177
  }
178
178
 
179
- /* A message of a server: one to show a person, or a line for its log. */
180
179
  export interface ServerMessage {
181
180
  readonly kind: 'show' | 'log';
182
181
  readonly type: MessageType;
package/src/session.ts CHANGED
@@ -85,7 +85,6 @@ export interface LspSessionOptions {
85
85
  locale?: string;
86
86
  }
87
87
 
88
- /* The capability that advertises each method statically. */
89
88
  const PROVIDERS: Record<string, keyof ServerCapabilities> = {
90
89
  'textDocument/completion': 'completionProvider',
91
90
  'completionItem/resolve': 'completionProvider',
@@ -186,7 +185,6 @@ function matches(options: ProviderOptions, document?: Pick<DocumentItem, 'uri' |
186
185
  );
187
186
  }
188
187
 
189
- /* Whether provider options cover a method that a provider only offers on top of its feature. */
190
188
  function offersMethod(method: string, options: ProviderOptions): boolean {
191
189
  if (method.endsWith('/resolve')) {
192
190
  return options.resolveProvider === true;
@@ -219,7 +217,6 @@ function offersMethod(method: string, options: ProviderOptions): boolean {
219
217
  return true;
220
218
  }
221
219
 
222
- /* One conversation with one language server: the handshake, what it can do, and the documents open in it. */
223
220
  export class LspSession {
224
221
  readonly connection: JsonRpcConnection;
225
222
  readonly options: LspSessionOptions;
@@ -497,12 +494,10 @@ export class LspSession {
497
494
  return this.request('workspace/textDocumentContent', { uri }, options);
498
495
  }
499
496
 
500
- /* Changes the trace level the server sends `$/logTrace` at. */
501
497
  setTrace(value: TraceValue): Promise<void> {
502
498
  return this.notify('$/setTrace', { value });
503
499
  }
504
500
 
505
- /* Asks the server to stop work it reported as cancellable under `token`. */
506
501
  cancelWorkDoneProgress(token: ProgressToken): Promise<void> {
507
502
  return this.notify('window/workDoneProgress/cancel', { token });
508
503
  }
@@ -643,7 +638,6 @@ export class LspSession {
643
638
  return this.askBefore('willRename', renamesTaken(this.fileOperationFilters('willRename'), files), options);
644
639
  }
645
640
 
646
- /* Tells the server which of these files moved, those its filters take. */
647
641
  async didRenameFiles(files: readonly RenamedFile[]): Promise<void> {
648
642
  await this.tellAfter('didRename', renamesTaken(this.fileOperationFilters('didRename'), files));
649
643
  }
@@ -653,7 +647,6 @@ export class LspSession {
653
647
  return this.askBefore('willCreate', createsTaken(this.fileOperationFilters('willCreate'), files), options);
654
648
  }
655
649
 
656
- /* Tells the server which of these files were made, those its filters take. */
657
650
  async didCreateFiles(files: readonly CreatedFile[]): Promise<void> {
658
651
  await this.tellAfter('didCreate', createsTaken(this.fileOperationFilters('didCreate'), files));
659
652
  }
@@ -663,7 +656,6 @@ export class LspSession {
663
656
  return this.askBefore('willDelete', deletesTaken(this.fileOperationFilters('willDelete'), files), options);
664
657
  }
665
658
 
666
- /* Tells the server which of these files were deleted, those its filters take. */
667
659
  async didDeleteFiles(files: readonly DeletedFile[]): Promise<void> {
668
660
  await this.tellAfter('didDelete', deletesTaken(this.fileOperationFilters('didDelete'), files));
669
661
  }
@@ -52,7 +52,6 @@ export class ScriptedTransport implements LspTransport {
52
52
  }
53
53
  }
54
54
 
55
- /* The last request of `method` the client sent. */
56
55
  request(method: string) {
57
56
  return this.sent.findLast((message) => 'method' in message && message.method === method && 'id' in message) as {
58
57
  id: number;
package/src/testing.ts CHANGED
@@ -92,7 +92,6 @@ export class FakeLanguageServer {
92
92
  this.connection.onRequest(method, handler);
93
93
  }
94
94
 
95
- /* The params of every request or notification of `method`, in the order they came. */
96
95
  paramsOf(method: string): unknown[] {
97
96
  return this.received.filter((message) => message.method === method).map((message) => message.params);
98
97
  }
@@ -7,7 +7,6 @@ type DocumentChange = NonNullable<WorkspaceEdit['documentChanges']>[number];
7
7
  /* The resource operations of the protocol; a host declares the ones it can carry out. */
8
8
  export type ResourceOperationKind = 'create' | 'rename' | 'delete';
9
9
 
10
- /* A text file as the host has it right now. */
11
10
  export interface WorkspaceEditText {
12
11
  readonly text: string;
13
12
  /* The version the language servers hold the document at; null when the host cannot tell. */
@@ -33,7 +32,6 @@ export interface WorkspaceEditSource {
33
32
  readonly operations: readonly ResourceOperationKind[];
34
33
  }
35
34
 
36
- /* Text edits to one file, with the text before and after. */
37
35
  export interface PlannedTextStep {
38
36
  readonly kind: 'edits';
39
37
  /* The URI the edit names, which is where the file stands once the earlier steps ran. */
@@ -61,7 +59,6 @@ export interface PlannedRenameStep {
61
59
  readonly kind: 'rename';
62
60
  readonly oldUri: string;
63
61
  readonly newUri: string;
64
- /* The target is there and is replaced. */
65
62
  readonly overwrite: boolean;
66
63
  }
67
64