mirror of
https://github.com/c-cube/linol.git
synced 2025-12-10 05:04:00 -05:00
107 lines
2.1 KiB
TypeScript
107 lines
2.1 KiB
TypeScript
import outdent from "outdent";
|
|
import * as Protocol from "vscode-languageserver-protocol";
|
|
import * as Types from "vscode-languageserver-types";
|
|
import * as LanguageServer from "../src/LanguageServer";
|
|
|
|
describe("textDocument/references", () => {
|
|
let languageServer: LanguageServer.LanguageServer;
|
|
|
|
function openDocument(source: string) {
|
|
languageServer.sendNotification(
|
|
Protocol.DidOpenTextDocumentNotification.type,
|
|
{
|
|
textDocument: Types.TextDocumentItem.create(
|
|
"file:///test.ml",
|
|
"ocaml",
|
|
0,
|
|
source,
|
|
),
|
|
},
|
|
);
|
|
}
|
|
|
|
async function query() {
|
|
return await languageServer.sendRequest("textDocument/codeLens", {
|
|
textDocument: Types.TextDocumentIdentifier.create("file:///test.ml"),
|
|
});
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
languageServer = await LanguageServer.startAndInitialize();
|
|
languageServer.sendNotification("workspace/didChangeConfiguration", {
|
|
settings: {
|
|
codelens: { enable: true },
|
|
},
|
|
});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await LanguageServer.exit(languageServer);
|
|
});
|
|
|
|
it("returns codeLens for a module", async () => {
|
|
openDocument(outdent`
|
|
let num = 42
|
|
let string = "Hello"
|
|
|
|
module M = struct
|
|
let m a b = a + b
|
|
end
|
|
`);
|
|
|
|
const result = await query();
|
|
|
|
expect(result).toMatchInlineSnapshot(`
|
|
[
|
|
{
|
|
"command": {
|
|
"command": "",
|
|
"title": "int -> int -> int",
|
|
},
|
|
"range": {
|
|
"end": {
|
|
"character": 19,
|
|
"line": 4,
|
|
},
|
|
"start": {
|
|
"character": 2,
|
|
"line": 4,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"command": {
|
|
"command": "",
|
|
"title": "string",
|
|
},
|
|
"range": {
|
|
"end": {
|
|
"character": 20,
|
|
"line": 1,
|
|
},
|
|
"start": {
|
|
"character": 0,
|
|
"line": 1,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"command": {
|
|
"command": "",
|
|
"title": "int",
|
|
},
|
|
"range": {
|
|
"end": {
|
|
"character": 12,
|
|
"line": 0,
|
|
},
|
|
"start": {
|
|
"character": 0,
|
|
"line": 0,
|
|
},
|
|
},
|
|
},
|
|
]
|
|
`);
|
|
});
|
|
});
|