@presolve/language-service 0.1.0-alpha.6
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 +21 -0
- package/package.json +25 -0
- package/src/index.js +21 -0
- package/test/smoke.mjs +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Presolve contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@presolve/language-service",
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
|
+
"description": "Compiler-product language-service queries for Presolve.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/fierstdev/presolve.git",
|
|
10
|
+
"directory": "packages/language-service"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"tag": "alpha"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/index.js"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@presolve/compiler-wasm": "0.1.0-alpha.6"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node test/smoke.mjs"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import initializeWasm, { query_snapshot_v1 } from "@presolve/compiler-wasm";
|
|
2
|
+
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the compiler-owned WASM artifact. The caller supplies its module
|
|
8
|
+
* bytes/path and keeps every query-snapshot byte sequence outside this package.
|
|
9
|
+
*/
|
|
10
|
+
export async function initializeLanguageService(moduleOrPath) {
|
|
11
|
+
await initializeWasm({ module_or_path: moduleOrPath });
|
|
12
|
+
return Object.freeze({ query });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Projects one caller-owned compiler product through the sole WASM authority.
|
|
17
|
+
*/
|
|
18
|
+
export function query(productBytes, request) {
|
|
19
|
+
const requestBytes = encoder.encode(`${JSON.stringify(request)}\n`);
|
|
20
|
+
return JSON.parse(decoder.decode(query_snapshot_v1(productBytes, requestBytes)));
|
|
21
|
+
}
|
package/test/smoke.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { initializeLanguageService } from "../src/index.js";
|
|
4
|
+
|
|
5
|
+
const product = await readFile(fileURLToPath(new URL("../../../crates/presolve_compiler/fixtures/tooling/query-snapshot-v1.json", import.meta.url)));
|
|
6
|
+
const snapshot = JSON.parse(product);
|
|
7
|
+
const wasm = await readFile(fileURLToPath(new URL("../../compiler-wasm/dist/presolve_compiler_wasm_bg.wasm", import.meta.url)));
|
|
8
|
+
const service = await initializeLanguageService(wasm);
|
|
9
|
+
const result = service.query(product, { schema: "presolve.language-service-wasm-request", version: 1, operation: "hover" });
|
|
10
|
+
if (result.status !== "unsupported" || result.capability !== "hover") throw new Error("language service must preserve the WASM result");
|
|
11
|
+
const position = service.query(product, { schema: "presolve.language-service-wasm-request", version: 1, operation: "position", sourceUnitId: snapshot.sourceUnits[0].sourceUnitId, offset: 114 });
|
|
12
|
+
if (position.status !== "ok" || position.result.records.length !== 6) throw new Error("language service must preserve WASM position records");
|