@bscotch/gml-language-server 0.0.0-stage → 1.1.1

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/LICENSE.md ADDED
@@ -0,0 +1,29 @@
1
+ # License for the Stitch Monorepo
2
+
3
+ License information for the content of this git repository. The various packages in this repo are developed by [Butterscotch Shenanigans](https://www.bscotch.net) ("Bscotch").
4
+
5
+ ## License files
6
+
7
+ Whenever a `LICENSE` file is found in a folder, or a license is specified by a `package.json` or similar manifest file, that license takes precedence for all files in that folder and its subfolders.
8
+
9
+ This is the root-most `LICENSE` file, and therefore dictates the default licensing in this repository.
10
+
11
+ ## Stitch name and logo
12
+
13
+ ![Stitch Logo](https://img.bscotch.net/fit-in/256x256/logos/stitch.png "The Stitch Logo, copyright and trademark Butterscotch Shenanigans, all rights reserved.")
14
+
15
+ Stitch™ and its logo are trademarks of Bscotch. Bscotch reserves all rights to Stitch and its logo.
16
+
17
+ Stitch Logo ©2022 by Bscotch. All rights reserved.
18
+
19
+ ## Other code and content
20
+
21
+ Everything found in this project, except for the Stitch name and logo as described above or unless otherwise specified by a more proximal LICENSE file, falls under the MIT license (https://opensource.org/license/mit/):
22
+
23
+ Copyright 2023 Butterscotch Shenanigans
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,75 @@
1
- # Temporary Holding Version
1
+ # @bscotch/gml-language-server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) server for GML (GameMaker Language). It provides editor features for a GameMaker project, built on [`@bscotch/gml-parser`](../parser/), [`@bscotch/gml-formatter`](../gml-formatter/) and [`@bscotch/gamemaker-project`](../gamemaker-project/).
4
+
5
+
6
+ ## Usage
7
+
8
+ Run it as a separate process:
9
+
10
+ ```sh
11
+ gml-language-server --stdio
12
+ ```
13
+
14
+ Or start it on any connection:
15
+
16
+ ```ts
17
+ import { startServer } from '@bscotch/gml-language-server';
18
+ import { createConnection, ProposedFeatures } from 'vscode-languageserver/node';
19
+
20
+ startServer(createConnection(ProposedFeatures.all));
21
+ ```
22
+
23
+ The client must pass the project's `.yyp` path in `initializationOptions` (see `GmlServerInitializationOptions` in [`src/protocol.ts`](./src/protocol.ts)):
24
+
25
+ ```json
26
+ {
27
+ "yypPath": "/path/to/project/project.yyp",
28
+ "specs": ["/path/to/runtime/GmlSpec.xml"],
29
+ "settings": { "format": { "preset": "bscotch" } }
30
+ }
31
+ ```
32
+
33
+ `specs` lists the `GmlSpec.xml` files that define GameMaker's built-in functions and constants. Usually these come from the project's runtime. Without them, the server uses the spec bundled with `@bscotch/gml-parser`.
34
+
35
+ Settings can be changed later with `workspace/didChangeConfiguration`, sending the same `GmlServerSettings` object as `settings`.
36
+
37
+ ## Features
38
+
39
+ - **Diagnostics** for every GML file in the project, kept up to date as files change. They include project-wide ones like unused functions. The optional checks (`missingDocs`, `mixedOperators`, `argumentEvaluationOrder`) and the severity of `argumentTypes` are set in the settings. So are asset-tree folders whose files get no diagnostics (`suppressGroups`).
40
+ - **Hover:** signatures, types, descriptions, struct and enum members, and frame previews for sprites.
41
+ - **Completion:**
42
+ - symbols in scope, and members after a `.`;
43
+ - new members inside a struct literal;
44
+ - doc-comment tags after `@`, and type names inside `{}`.
45
+ - **Signature help.**
46
+ - **Go to definition and type definition.**
47
+ - `event_inherited()` goes to the same event in the nearest ancestor that has it.
48
+ - Assets go to their main file (an object's Create event, a shader's fragment shader, a sound's audio file, ...).
49
+ - **References and rename.** Built-ins and assets can't be renamed; the error says why.
50
+ - **Semantic tokens and workspace symbols.** Workspace symbols include assets, and the local variables of the file in the active editor (which the client reports with `stitch/activeDocument`).
51
+ - **Formatting** with `@bscotch/gml-formatter` (the `bscotch` preset by default, or `standard`). Files with syntax errors are left alone.
52
+
53
+ ### Stitch messages
54
+
55
+ | Message | Direction | Purpose |
56
+ | --- | --- | --- |
57
+ | `stitch/status` | server → client | Loading progress: `loading`, `ready` (with file count and time), or `error`. |
58
+ | `stitch/symbolInfo` | client → server | Describe the symbol at a position (its kind, whether it's built-in, its asset kind and type). Clients use this for commands like "copy type" or "edit sprite". |
59
+ | `stitch/activeDocument` | client → server | Which document is in the active editor (`uri: null` for none). Only its local variables are included in workspace symbols. |
60
+ | `stitch/globalNames` | client → server | The names of the project's global symbols (not built-ins). |
61
+ | `stitch/assetRenameEdits` | client → server | The code edits that rename every reference to an asset, as a `WorkspaceEdit`. The client renames the asset's files itself. |
62
+
63
+ ## Design
64
+
65
+ - **The server never writes to the project.** It keeps a read-only `GameMakerProject` that follows file changes. Clients forward their file watcher's events with `workspace/didChangeWatchedFiles`. Changing the project (creating, renaming or deleting assets, and so on) is the client's job. That keeps one writer per project, while the server always sees what's on disk.
66
+ - **Open documents override disk.** An open document's text is analyzed instead of its file. When it closes, the file on disk is used again.
67
+ - **Requests see up-to-date results.** Edits are re-analyzed shortly after they happen, and any request on a file with pending edits brings the analysis up to date first. Diagnostics for changed and open files are published right away, and every other file's diagnostics are re-checked once edits settle. Only diagnostics that actually changed are sent.
68
+
69
+ ## Testing
70
+
71
+ ```sh
72
+ pnpm test
73
+ ```
74
+
75
+ `src/server.test.ts` starts the server in-process and talks to it over a JSON-RPC connection, using a copy of `../parser/samples/project`.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run the language server. Pass `--stdio`, `--node-ipc` or
4
+ * `--socket=<port>` to choose how it talks to the client.
5
+ */
6
+ import { runServer } from "./index.js";
7
+ runServer();
8
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,SAAS,EAAE,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * LSP features, as functions from a session and a file position to LSP
3
+ * results. These are pure translations of `GmlQueries` results (plus some
4
+ * project knowledge, like where an asset's files are).
5
+ */
6
+ import type { Asset } from '@bscotch/gamemaker-project';
7
+ import { type DiagnosticOptions, type FunctionEntry, type Location as GmlLocation, type SymbolEntry } from '@bscotch/gml-parser';
8
+ import { LineIndex } from '@bscotch/gml-syntax';
9
+ import { type CompletionItem, type Diagnostic, type Hover, type Location, type Range, type SemanticTokens, type SignatureHelp, type SymbolInformation, type TextEdit, type WorkspaceEdit } from 'vscode-languageserver/node';
10
+ import { type DiagnosticLevel, type GmlServerSettings, type SymbolInfo } from './protocol.ts';
11
+ import type { ProjectSession } from './session.ts';
12
+ /** The line index for a file: from its analysis, else read from disk */
13
+ export declare function linesOf(session: ProjectSession, fileId: string): LineIndex;
14
+ export declare function rangeOf(lines: LineIndex, start: number, end: number): Range;
15
+ export declare function toLocation(session: ProjectSession, loc: GmlLocation, lines?: LineIndex): Location;
16
+ export declare function diagnosticOptions(settings: GmlServerSettings): DiagnosticOptions;
17
+ /** Whether a file is in a folder whose diagnostics are suppressed */
18
+ export declare function isSuppressed(session: ProjectSession, fileId: string, settings: GmlServerSettings): boolean;
19
+ export declare function diagnostics(session: ProjectSession, fileId: string, settings: GmlServerSettings): Diagnostic[];
20
+ export declare function isDiagnosticLevel(value: unknown): value is DiagnosticLevel;
21
+ export declare function hover(session: ProjectSession, fileId: string, offset: number): Hover | null;
22
+ /** Where to go to "see" an asset: an object's Create event, a sound's file, ... */
23
+ export declare function assetLocation(asset: Asset): Location;
24
+ export declare function definition(session: ProjectSession, fileId: string, offset: number): Location[];
25
+ export declare function typeDefinition(session: ProjectSession, fileId: string, offset: number): Location[];
26
+ export declare function references(session: ProjectSession, fileId: string, offset: number, includeDeclaration: boolean): Location[];
27
+ export declare class RenameError extends Error {
28
+ }
29
+ /** The range to rename, or throws a {@link RenameError} saying why it can't be */
30
+ export declare function prepareRename(session: ProjectSession, fileId: string, offset: number): Range;
31
+ export declare function rename(session: ProjectSession, fileId: string, offset: number, newName: string): WorkspaceEdit;
32
+ /** The code edits for renaming an asset (its files are renamed separately) */
33
+ export declare function assetRenameEdits(session: ProjectSession, name: string, newName: string): WorkspaceEdit;
34
+ export declare function completions(session: ProjectSession, fileId: string, offset: number, triggerCharacter: string | undefined, settings: GmlServerSettings): CompletionItem[] | null;
35
+ /** A function's signature, with each parameter's position in it */
36
+ export declare function signatureParts(session: ProjectSession, fn: FunctionEntry): {
37
+ label: string;
38
+ params: {
39
+ symbol: SymbolEntry | undefined;
40
+ range: [number, number];
41
+ }[];
42
+ };
43
+ export declare function signatureHelp(session: ProjectSession, fileId: string, offset: number): SignatureHelp | null;
44
+ export declare function semanticTokens(session: ProjectSession, fileId: string): SemanticTokens;
45
+ export declare function workspaceSymbols(session: ProjectSession, query: string, settings: GmlServerSettings,
46
+ /** The file in the active editor, whose local variables are included */
47
+ activeFileId?: string): SymbolInformation[];
48
+ export declare function symbolInfo(session: ProjectSession, fileId: string, offset: number): SymbolInfo | null;
49
+ export declare function formatDocument(text: string, settings: GmlServerSettings): {
50
+ edits: TextEdit[];
51
+ error?: string;
52
+ };
53
+ //# sourceMappingURL=features.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,QAAQ,IAAI,WAAW,EAC5B,KAAK,WAAW,EAEjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,aAAa,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAKnD,wEAAwE;AACxE,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAU1E;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAE3E;AAED,wBAAgB,UAAU,CACxB,OAAO,EAAE,cAAc,EACvB,GAAG,EAAE,WAAW,EAChB,KAAK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