@emnudge/wat-lsp 0.1.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.
- package/README.md +119 -0
- package/dist/index.d.ts +216 -0
- package/dist/index.js +201 -0
- package/dist/wasm/tree-sitter.wasm +0 -0
- package/dist/wasm/wat_lsp_rust.d.ts +132 -0
- package/dist/wasm/wat_lsp_rust.js +811 -0
- package/dist/wasm/wat_lsp_rust_bg.wasm +0 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @emnudge/wat-lsp
|
|
2
|
+
|
|
3
|
+
WebAssembly Text Format (WAT) Language Server - WASM build for browser and Node.js.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @emnudge/wat-lsp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { createWatLSP } from '@emnudge/wat-lsp';
|
|
17
|
+
|
|
18
|
+
// Create and initialize the LSP
|
|
19
|
+
const lsp = await createWatLSP();
|
|
20
|
+
|
|
21
|
+
// Parse a WAT document
|
|
22
|
+
lsp.parse(`
|
|
23
|
+
(module
|
|
24
|
+
(func $add (param $a i32) (param $b i32) (result i32)
|
|
25
|
+
local.get $a
|
|
26
|
+
local.get $b
|
|
27
|
+
i32.add
|
|
28
|
+
)
|
|
29
|
+
(export "add" (func $add))
|
|
30
|
+
)
|
|
31
|
+
`);
|
|
32
|
+
|
|
33
|
+
// Get hover information
|
|
34
|
+
const hover = lsp.provideHover(2, 12); // line 2, column 12
|
|
35
|
+
console.log(hover?.contents.value);
|
|
36
|
+
|
|
37
|
+
// Get diagnostics (syntax errors)
|
|
38
|
+
const diagnostics = lsp.provideDiagnostics();
|
|
39
|
+
|
|
40
|
+
// Go to definition
|
|
41
|
+
const definition = lsp.provideDefinition(5, 16);
|
|
42
|
+
|
|
43
|
+
// Find references
|
|
44
|
+
const references = lsp.provideReferences(2, 12, true);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### With Custom WASM Paths
|
|
48
|
+
|
|
49
|
+
When bundling for a web application, you may need to serve the WASM files from a specific location:
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
import { createWatLSP, assets } from '@emnudge/wat-lsp';
|
|
53
|
+
|
|
54
|
+
// Use custom paths
|
|
55
|
+
const lsp = await createWatLSP({
|
|
56
|
+
treeSitterWasmPath: '/assets/tree-sitter.wasm',
|
|
57
|
+
watLspWasmPath: '/assets/wat_lsp_rust_bg.wasm',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Or use the bundled asset URLs directly
|
|
61
|
+
console.log(assets.treeSitterWasm); // URL to bundled tree-sitter.wasm
|
|
62
|
+
console.log(assets.watLspWasm); // URL to bundled wat_lsp_rust_bg.wasm
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Using the WatLanguageServer Class
|
|
66
|
+
|
|
67
|
+
For a more LSP-like interface:
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
import { WatLanguageServer } from '@emnudge/wat-lsp';
|
|
71
|
+
|
|
72
|
+
const server = new WatLanguageServer();
|
|
73
|
+
await server.initialize();
|
|
74
|
+
|
|
75
|
+
// Update document
|
|
76
|
+
server.updateDocument('(module (func $foo))');
|
|
77
|
+
|
|
78
|
+
// Use LSP-style methods
|
|
79
|
+
const hover = server.provideHover(0, 15);
|
|
80
|
+
const diagnostics = server.provideDiagnostics();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Low-level WASM Access
|
|
84
|
+
|
|
85
|
+
For advanced usage, you can access the raw WASM bindings:
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
import { WatLSP, initWasm } from '@emnudge/wat-lsp';
|
|
89
|
+
import { Parser } from 'web-tree-sitter';
|
|
90
|
+
|
|
91
|
+
// Initialize tree-sitter yourself
|
|
92
|
+
await Parser.init({
|
|
93
|
+
locateFile: (file) => `/my-path/${file}`,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Initialize the WASM module
|
|
97
|
+
await initWasm('/my-path/wat_lsp_rust_bg.wasm');
|
|
98
|
+
|
|
99
|
+
// Create and use WatLSP directly
|
|
100
|
+
const lsp = new WatLSP();
|
|
101
|
+
await lsp.initialize();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Features
|
|
105
|
+
|
|
106
|
+
- **Hover**: Get documentation for WAT instructions and symbols
|
|
107
|
+
- **Go to Definition**: Jump to function, global, and type definitions
|
|
108
|
+
- **Find References**: Find all usages of a symbol
|
|
109
|
+
- **Diagnostics**: Syntax error detection using `wast` parser
|
|
110
|
+
- **Semantic Tokens**: Tree-sitter based syntax highlighting
|
|
111
|
+
|
|
112
|
+
## Requirements
|
|
113
|
+
|
|
114
|
+
- Modern browser with WebAssembly support, or Node.js 16+
|
|
115
|
+
- `web-tree-sitter` (peer dependency)
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @emnudge/wat-lsp - WebAssembly Text Format Language Server
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { WatLSP } from './wasm/wat_lsp_rust.js';
|
|
6
|
+
export { default as initWasm } from './wasm/wat_lsp_rust.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* LSP Position
|
|
10
|
+
*/
|
|
11
|
+
export interface Position {
|
|
12
|
+
line: number;
|
|
13
|
+
character: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* LSP Range
|
|
18
|
+
*/
|
|
19
|
+
export interface Range {
|
|
20
|
+
start: Position;
|
|
21
|
+
end: Position;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Hover result from the LSP
|
|
26
|
+
*/
|
|
27
|
+
export interface HoverResult {
|
|
28
|
+
contents: {
|
|
29
|
+
kind: 'markdown' | 'plaintext';
|
|
30
|
+
value: string;
|
|
31
|
+
};
|
|
32
|
+
range?: Range;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Definition result from the LSP
|
|
37
|
+
*/
|
|
38
|
+
export interface DefinitionResult {
|
|
39
|
+
range: Range;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Reference result from the LSP
|
|
44
|
+
*/
|
|
45
|
+
export interface ReferenceResult {
|
|
46
|
+
range: Range;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Diagnostic from the LSP
|
|
51
|
+
*/
|
|
52
|
+
export interface Diagnostic {
|
|
53
|
+
range: Range;
|
|
54
|
+
message: string;
|
|
55
|
+
severity: 1 | 2 | 3 | 4; // Error, Warning, Info, Hint
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Completion item from the LSP
|
|
60
|
+
*/
|
|
61
|
+
export interface CompletionItem {
|
|
62
|
+
label: string;
|
|
63
|
+
kind?: number;
|
|
64
|
+
detail?: string;
|
|
65
|
+
insertText?: string;
|
|
66
|
+
insertTextRules?: number;
|
|
67
|
+
documentation?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Semantic tokens legend
|
|
72
|
+
*/
|
|
73
|
+
export interface SemanticTokensLegend {
|
|
74
|
+
tokenTypes: string[];
|
|
75
|
+
tokenModifiers: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Server capabilities
|
|
80
|
+
*/
|
|
81
|
+
export interface ServerCapabilities {
|
|
82
|
+
hoverProvider: boolean;
|
|
83
|
+
definitionProvider: boolean;
|
|
84
|
+
referencesProvider: boolean;
|
|
85
|
+
documentSymbolProvider: boolean;
|
|
86
|
+
completionProvider: boolean;
|
|
87
|
+
semanticTokensProvider: {
|
|
88
|
+
legend: SemanticTokensLegend;
|
|
89
|
+
full: boolean;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Path helpers for locating bundled WASM assets
|
|
95
|
+
*/
|
|
96
|
+
export const assets: {
|
|
97
|
+
/** URL to tree-sitter.wasm */
|
|
98
|
+
treeSitterWasm: string;
|
|
99
|
+
/** URL to wat_lsp_rust_bg.wasm */
|
|
100
|
+
watLspWasm: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Options for createWatLSP
|
|
105
|
+
*/
|
|
106
|
+
export interface CreateWatLSPOptions {
|
|
107
|
+
/** Custom path to tree-sitter.wasm */
|
|
108
|
+
treeSitterWasmPath?: string;
|
|
109
|
+
/** Custom path to wat_lsp_rust_bg.wasm */
|
|
110
|
+
watLspWasmPath?: string;
|
|
111
|
+
/** Skip tree-sitter initialization if already done */
|
|
112
|
+
skipTreeSitterInit?: boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create and initialize a WAT Language Server instance.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* const lsp = await createWatLSP();
|
|
120
|
+
* lsp.parse('(module (func $add (param i32 i32) (result i32)))');
|
|
121
|
+
* const hover = lsp.provideHover(0, 15);
|
|
122
|
+
*/
|
|
123
|
+
export function createWatLSP(options?: CreateWatLSPOptions): Promise<WatLSP>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* WAT Language Server instance (from WASM)
|
|
127
|
+
*/
|
|
128
|
+
export interface WatLSP {
|
|
129
|
+
/** Check if the LSP is ready */
|
|
130
|
+
readonly ready: boolean;
|
|
131
|
+
|
|
132
|
+
/** Initialize the LSP (loads tree-sitter) */
|
|
133
|
+
initialize(): Promise<boolean>;
|
|
134
|
+
|
|
135
|
+
/** Parse a WAT document */
|
|
136
|
+
parse(document: string): void;
|
|
137
|
+
|
|
138
|
+
/** Provide hover information at position */
|
|
139
|
+
provideHover(line: number, col: number): HoverResult | null;
|
|
140
|
+
|
|
141
|
+
/** Provide go-to-definition at position */
|
|
142
|
+
provideDefinition(line: number, col: number): DefinitionResult | null;
|
|
143
|
+
|
|
144
|
+
/** Provide find-references at position */
|
|
145
|
+
provideReferences(
|
|
146
|
+
line: number,
|
|
147
|
+
col: number,
|
|
148
|
+
includeDeclaration: boolean
|
|
149
|
+
): ReferenceResult[];
|
|
150
|
+
|
|
151
|
+
/** Provide diagnostics for the current document */
|
|
152
|
+
provideDiagnostics(): Diagnostic[];
|
|
153
|
+
|
|
154
|
+
/** Provide code completion at position */
|
|
155
|
+
provideCompletion(line: number, col: number): CompletionItem[];
|
|
156
|
+
|
|
157
|
+
/** Provide semantic tokens for syntax highlighting */
|
|
158
|
+
provideSemanticTokens(): Uint32Array;
|
|
159
|
+
|
|
160
|
+
/** Get the semantic tokens legend */
|
|
161
|
+
getSemanticTokensLegend(): SemanticTokensLegend;
|
|
162
|
+
|
|
163
|
+
/** Get symbol table as HTML (for debugging) */
|
|
164
|
+
getSymbolTableHTML(): string;
|
|
165
|
+
|
|
166
|
+
/** Debug: get word info at position */
|
|
167
|
+
debugWordAt(line: number, col: number): {
|
|
168
|
+
word: string | null;
|
|
169
|
+
hasFunction?: boolean;
|
|
170
|
+
functionRange?: string;
|
|
171
|
+
functionLine?: number | null;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* LSP-like message handler wrapper.
|
|
177
|
+
* Provides a cleaner interface for the WAT LSP.
|
|
178
|
+
*/
|
|
179
|
+
export class WatLanguageServer {
|
|
180
|
+
/** Check if the server is ready */
|
|
181
|
+
readonly ready: boolean;
|
|
182
|
+
|
|
183
|
+
/** Initialize the language server */
|
|
184
|
+
initialize(options?: CreateWatLSPOptions): Promise<{ capabilities: ServerCapabilities }>;
|
|
185
|
+
|
|
186
|
+
/** Get server capabilities */
|
|
187
|
+
getCapabilities(): ServerCapabilities;
|
|
188
|
+
|
|
189
|
+
/** Update the document content */
|
|
190
|
+
updateDocument(content: string): void;
|
|
191
|
+
|
|
192
|
+
/** Provide hover information */
|
|
193
|
+
provideHover(line: number, character: number): HoverResult | null;
|
|
194
|
+
|
|
195
|
+
/** Provide go-to-definition */
|
|
196
|
+
provideDefinition(line: number, character: number): DefinitionResult | null;
|
|
197
|
+
|
|
198
|
+
/** Provide find-references */
|
|
199
|
+
provideReferences(
|
|
200
|
+
line: number,
|
|
201
|
+
character: number,
|
|
202
|
+
includeDeclaration?: boolean
|
|
203
|
+
): ReferenceResult[];
|
|
204
|
+
|
|
205
|
+
/** Provide diagnostics */
|
|
206
|
+
provideDiagnostics(): Diagnostic[];
|
|
207
|
+
|
|
208
|
+
/** Provide code completion */
|
|
209
|
+
provideCompletion(line: number, character: number): CompletionItem[];
|
|
210
|
+
|
|
211
|
+
/** Provide semantic tokens */
|
|
212
|
+
provideSemanticTokens(): Uint32Array;
|
|
213
|
+
|
|
214
|
+
/** Get semantic tokens legend */
|
|
215
|
+
getSemanticTokensLegend(): SemanticTokensLegend;
|
|
216
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @emnudge/wat-lsp - WebAssembly Text Format Language Server
|
|
3
|
+
*
|
|
4
|
+
* A WASM-based language server for WAT files that runs in the browser or Node.js.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Parser } from 'web-tree-sitter';
|
|
8
|
+
|
|
9
|
+
// Re-export the raw WASM bindings for advanced usage
|
|
10
|
+
export { WatLSP } from './wasm/wat_lsp_rust.js';
|
|
11
|
+
export { default as initWasm } from './wasm/wat_lsp_rust.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Path helpers for locating bundled WASM assets.
|
|
15
|
+
* Use these when you need to serve the WASM files from a specific location.
|
|
16
|
+
*/
|
|
17
|
+
export const assets = {
|
|
18
|
+
/**
|
|
19
|
+
* Get the path to tree-sitter.wasm relative to this package.
|
|
20
|
+
* You'll need to serve this file and configure web-tree-sitter to find it.
|
|
21
|
+
*/
|
|
22
|
+
treeSitterWasm: new URL('./wasm/tree-sitter.wasm', import.meta.url).href,
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the path to the main wat-lsp WASM module.
|
|
26
|
+
*/
|
|
27
|
+
watLspWasm: new URL('./wasm/wat_lsp_rust_bg.wasm', import.meta.url).href,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create and initialize a WAT Language Server instance.
|
|
32
|
+
*
|
|
33
|
+
* This is a convenience function that handles all the initialization steps:
|
|
34
|
+
* 1. Initialize web-tree-sitter runtime
|
|
35
|
+
* 2. Initialize the wat-lsp WASM module
|
|
36
|
+
* 3. Create and initialize the WatLSP instance
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} options - Configuration options
|
|
39
|
+
* @param {string} [options.treeSitterWasmPath] - Custom path to tree-sitter.wasm
|
|
40
|
+
* @param {string} [options.watLspWasmPath] - Custom path to wat_lsp_rust_bg.wasm
|
|
41
|
+
* @param {boolean} [options.skipTreeSitterInit=false] - Skip tree-sitter init if already done
|
|
42
|
+
* @returns {Promise<import('./wasm/wat_lsp_rust.js').WatLSP>} Initialized WatLSP instance
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Basic usage
|
|
46
|
+
* const lsp = await createWatLSP();
|
|
47
|
+
* lsp.parse('(module (func $add (param i32 i32) (result i32)))');
|
|
48
|
+
* const hover = lsp.provideHover(0, 15);
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // With custom paths (e.g., when bundling for a web app)
|
|
52
|
+
* const lsp = await createWatLSP({
|
|
53
|
+
* treeSitterWasmPath: '/assets/tree-sitter.wasm',
|
|
54
|
+
* watLspWasmPath: '/assets/wat_lsp_rust_bg.wasm'
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
export async function createWatLSP(options = {}) {
|
|
58
|
+
const {
|
|
59
|
+
treeSitterWasmPath,
|
|
60
|
+
watLspWasmPath,
|
|
61
|
+
skipTreeSitterInit = false,
|
|
62
|
+
} = options;
|
|
63
|
+
|
|
64
|
+
// Step 1: Initialize web-tree-sitter (if not already done)
|
|
65
|
+
if (!skipTreeSitterInit) {
|
|
66
|
+
await Parser.init({
|
|
67
|
+
locateFile: (file) => {
|
|
68
|
+
if (file === 'tree-sitter.wasm') {
|
|
69
|
+
return treeSitterWasmPath || assets.treeSitterWasm;
|
|
70
|
+
}
|
|
71
|
+
return file;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Step 2: Initialize the WASM module
|
|
77
|
+
const { default: initWasm, WatLSP } = await import('./wasm/wat_lsp_rust.js');
|
|
78
|
+
await initWasm(watLspWasmPath || assets.watLspWasm);
|
|
79
|
+
|
|
80
|
+
// Step 3: Create and initialize the LSP instance
|
|
81
|
+
const lsp = new WatLSP();
|
|
82
|
+
const success = await lsp.initialize();
|
|
83
|
+
|
|
84
|
+
if (!success) {
|
|
85
|
+
throw new Error('Failed to initialize WAT LSP');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return lsp;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* LSP-like message handler wrapper.
|
|
93
|
+
* Provides a JSON-RPC style interface for the WAT LSP.
|
|
94
|
+
*
|
|
95
|
+
* Note: This is a simplified wrapper, not a full LSP implementation.
|
|
96
|
+
* For a complete LSP server, you'd need to handle all LSP methods and lifecycle.
|
|
97
|
+
*/
|
|
98
|
+
export class WatLanguageServer {
|
|
99
|
+
/** @type {import('./wasm/wat_lsp_rust.js').WatLSP | null} */
|
|
100
|
+
#lsp = null;
|
|
101
|
+
|
|
102
|
+
/** @type {string} */
|
|
103
|
+
#currentDocument = '';
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Check if the server is ready
|
|
107
|
+
*/
|
|
108
|
+
get ready() {
|
|
109
|
+
return this.#lsp?.ready ?? false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Initialize the language server
|
|
114
|
+
* @param {Object} options - Same options as createWatLSP
|
|
115
|
+
*/
|
|
116
|
+
async initialize(options = {}) {
|
|
117
|
+
this.#lsp = await createWatLSP(options);
|
|
118
|
+
return { capabilities: this.getCapabilities() };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get server capabilities
|
|
123
|
+
*/
|
|
124
|
+
getCapabilities() {
|
|
125
|
+
return {
|
|
126
|
+
hoverProvider: true,
|
|
127
|
+
definitionProvider: true,
|
|
128
|
+
referencesProvider: true,
|
|
129
|
+
documentSymbolProvider: false, // Not implemented yet
|
|
130
|
+
completionProvider: false, // Uses static completions
|
|
131
|
+
semanticTokensProvider: {
|
|
132
|
+
legend: this.#lsp?.getSemanticTokensLegend() ?? { tokenTypes: [], tokenModifiers: [] },
|
|
133
|
+
full: true,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Update the document content
|
|
140
|
+
* @param {string} content - The new document content
|
|
141
|
+
*/
|
|
142
|
+
updateDocument(content) {
|
|
143
|
+
this.#currentDocument = content;
|
|
144
|
+
this.#lsp?.parse(content);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Provide hover information
|
|
149
|
+
* @param {number} line - 0-indexed line number
|
|
150
|
+
* @param {number} character - 0-indexed character position
|
|
151
|
+
* @returns {Object|null} Hover result or null
|
|
152
|
+
*/
|
|
153
|
+
provideHover(line, character) {
|
|
154
|
+
return this.#lsp?.provideHover(line, character) ?? null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Provide go-to-definition
|
|
159
|
+
* @param {number} line - 0-indexed line number
|
|
160
|
+
* @param {number} character - 0-indexed character position
|
|
161
|
+
* @returns {Object|null} Definition location or null
|
|
162
|
+
*/
|
|
163
|
+
provideDefinition(line, character) {
|
|
164
|
+
return this.#lsp?.provideDefinition(line, character) ?? null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Provide find-references
|
|
169
|
+
* @param {number} line - 0-indexed line number
|
|
170
|
+
* @param {number} character - 0-indexed character position
|
|
171
|
+
* @param {boolean} includeDeclaration - Whether to include the declaration
|
|
172
|
+
* @returns {Array} Array of reference locations
|
|
173
|
+
*/
|
|
174
|
+
provideReferences(line, character, includeDeclaration = true) {
|
|
175
|
+
return this.#lsp?.provideReferences(line, character, includeDeclaration) ?? [];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Provide diagnostics for the current document
|
|
180
|
+
* @returns {Array} Array of diagnostic objects
|
|
181
|
+
*/
|
|
182
|
+
provideDiagnostics() {
|
|
183
|
+
return this.#lsp?.provideDiagnostics() ?? [];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Provide semantic tokens for syntax highlighting
|
|
188
|
+
* @returns {Uint32Array} Delta-encoded semantic tokens
|
|
189
|
+
*/
|
|
190
|
+
provideSemanticTokens() {
|
|
191
|
+
return this.#lsp?.provideSemanticTokens() ?? new Uint32Array(0);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Get the semantic tokens legend
|
|
196
|
+
* @returns {Object} Token types and modifiers
|
|
197
|
+
*/
|
|
198
|
+
getSemanticTokensLegend() {
|
|
199
|
+
return this.#lsp?.getSemanticTokensLegend() ?? { tokenTypes: [], tokenModifiers: [] };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class WatLSP {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the LSP (initializes tree-sitter). Returns true if successful.
|
|
9
|
+
*/
|
|
10
|
+
initialize(): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Debug: get info about a word at position
|
|
13
|
+
*/
|
|
14
|
+
debugWordAt(line: number, col: number): any;
|
|
15
|
+
/**
|
|
16
|
+
* Provide hover information at the given position (uses tree-sitter based hover)
|
|
17
|
+
*/
|
|
18
|
+
provideHover(line: number, col: number): any;
|
|
19
|
+
/**
|
|
20
|
+
* Provide code completion items at the given position
|
|
21
|
+
* Returns an array of completion item objects
|
|
22
|
+
*/
|
|
23
|
+
provideCompletion(line: number, col: number): any;
|
|
24
|
+
/**
|
|
25
|
+
* Provide go-to-definition at the given position
|
|
26
|
+
*/
|
|
27
|
+
provideDefinition(line: number, col: number): any;
|
|
28
|
+
/**
|
|
29
|
+
* Provide find-references at the given position
|
|
30
|
+
*/
|
|
31
|
+
provideReferences(line: number, col: number, include_declaration: boolean): any;
|
|
32
|
+
/**
|
|
33
|
+
* Get diagnostics (syntax errors) for the current document
|
|
34
|
+
*/
|
|
35
|
+
provideDiagnostics(): any;
|
|
36
|
+
/**
|
|
37
|
+
* Get symbol table as HTML for debugging
|
|
38
|
+
*/
|
|
39
|
+
getSymbolTableHTML(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Provide folding ranges for the current document
|
|
42
|
+
* Returns an array of folding range objects with startLine, endLine, and kind
|
|
43
|
+
*/
|
|
44
|
+
provideFoldingRanges(): any;
|
|
45
|
+
/**
|
|
46
|
+
* Provide semantic tokens for syntax highlighting
|
|
47
|
+
* Returns a flat array of u32 values in Monaco's delta-encoded format:
|
|
48
|
+
* [deltaLine, deltaStartChar, length, tokenType, tokenModifiers, ...]
|
|
49
|
+
*/
|
|
50
|
+
provideSemanticTokens(): Uint32Array;
|
|
51
|
+
/**
|
|
52
|
+
* Provide document symbols (outline) for the current document
|
|
53
|
+
* Returns a hierarchical array of symbols matching the LSP DocumentSymbol structure
|
|
54
|
+
*/
|
|
55
|
+
provideDocumentSymbols(): any;
|
|
56
|
+
/**
|
|
57
|
+
* Get the semantic token legend (token types and modifiers)
|
|
58
|
+
*/
|
|
59
|
+
getSemanticTokensLegend(): any;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new WAT LSP instance
|
|
62
|
+
*/
|
|
63
|
+
constructor();
|
|
64
|
+
/**
|
|
65
|
+
* Parse a WAT document and build symbol table using tree-sitter
|
|
66
|
+
*/
|
|
67
|
+
parse(document: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Check if the LSP is ready
|
|
70
|
+
*/
|
|
71
|
+
readonly ready: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Initialize panic hook for better error messages in the browser console
|
|
76
|
+
*/
|
|
77
|
+
export function init(): void;
|
|
78
|
+
|
|
79
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
80
|
+
|
|
81
|
+
export interface InitOutput {
|
|
82
|
+
readonly memory: WebAssembly.Memory;
|
|
83
|
+
readonly __wbg_watlsp_free: (a: number, b: number) => void;
|
|
84
|
+
readonly watlsp_debugWordAt: (a: number, b: number, c: number) => any;
|
|
85
|
+
readonly watlsp_getSemanticTokensLegend: (a: number) => any;
|
|
86
|
+
readonly watlsp_getSymbolTableHTML: (a: number) => [number, number];
|
|
87
|
+
readonly watlsp_initialize: (a: number) => any;
|
|
88
|
+
readonly watlsp_new: () => number;
|
|
89
|
+
readonly watlsp_parse: (a: number, b: number, c: number) => void;
|
|
90
|
+
readonly watlsp_provideCompletion: (a: number, b: number, c: number) => any;
|
|
91
|
+
readonly watlsp_provideDefinition: (a: number, b: number, c: number) => any;
|
|
92
|
+
readonly watlsp_provideDiagnostics: (a: number) => any;
|
|
93
|
+
readonly watlsp_provideDocumentSymbols: (a: number) => any;
|
|
94
|
+
readonly watlsp_provideFoldingRanges: (a: number) => any;
|
|
95
|
+
readonly watlsp_provideHover: (a: number, b: number, c: number) => any;
|
|
96
|
+
readonly watlsp_provideReferences: (a: number, b: number, c: number, d: number) => any;
|
|
97
|
+
readonly watlsp_provideSemanticTokens: (a: number) => any;
|
|
98
|
+
readonly watlsp_ready: (a: number) => number;
|
|
99
|
+
readonly init: () => void;
|
|
100
|
+
readonly wasm_bindgen__convert__closures_____invoke__hc43d41e9321ebc8f: (a: number, b: number, c: any) => void;
|
|
101
|
+
readonly wasm_bindgen__closure__destroy__hb94a2c2b7eee95bf: (a: number, b: number) => void;
|
|
102
|
+
readonly wasm_bindgen__convert__closures_____invoke__h17d4e94d5fe1e6e2: (a: number, b: number, c: any, d: any) => void;
|
|
103
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
104
|
+
readonly __externref_table_alloc: () => number;
|
|
105
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
106
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
107
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
108
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
109
|
+
readonly __wbindgen_start: () => void;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
116
|
+
* a precompiled `WebAssembly.Module`.
|
|
117
|
+
*
|
|
118
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
119
|
+
*
|
|
120
|
+
* @returns {InitOutput}
|
|
121
|
+
*/
|
|
122
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
126
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
127
|
+
*
|
|
128
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
129
|
+
*
|
|
130
|
+
* @returns {Promise<InitOutput>}
|
|
131
|
+
*/
|
|
132
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|