mirror of
https://github.com/c-cube/linol.git
synced 2025-12-11 05:28:35 -05:00
111 lines
2.5 KiB
TypeScript
111 lines
2.5 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/completion", () => {
|
|
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 queryCompletionItemResolve(
|
|
label: string,
|
|
position: Types.Position,
|
|
) {
|
|
return languageServer.sendRequest("completionItem/resolve", {
|
|
label: label,
|
|
data: {
|
|
textDocument: {
|
|
uri: "file:///test.ml",
|
|
},
|
|
position: position,
|
|
},
|
|
});
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
languageServer = await LanguageServer.startAndInitialize();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await LanguageServer.exit(languageServer);
|
|
});
|
|
|
|
it("can get documentation for the end of document", async () => {
|
|
openDocument(outdent`
|
|
List.ma
|
|
`);
|
|
|
|
const response = await queryCompletionItemResolve(
|
|
"map2",
|
|
Types.Position.create(0, 5),
|
|
);
|
|
|
|
expect(response).toMatchInlineSnapshot(`
|
|
{
|
|
"documentation": "[map2 f [a1; ...; an] [b1; ...; bn]] is
|
|
[[f a1 b1; ...; f an bn]].
|
|
@raise Invalid_argument if the two lists are determined
|
|
to have different lengths.",
|
|
"label": "map2",
|
|
}
|
|
`);
|
|
});
|
|
|
|
it("can get documentation at arbitrary position", async () => {
|
|
openDocument(outdent`
|
|
List.fld((=) 0) [1; 2; 3]
|
|
`);
|
|
|
|
const response = await queryCompletionItemResolve(
|
|
"find_all",
|
|
Types.Position.create(0, 5),
|
|
);
|
|
|
|
expect(response).toMatchInlineSnapshot(`
|
|
{
|
|
"documentation": "[find_all] is another name for {!filter}.",
|
|
"label": "find_all",
|
|
}
|
|
`);
|
|
});
|
|
|
|
it("can get documentation at arbitrary position (before dot)", async () => {
|
|
openDocument(outdent`
|
|
module Outer = struct
|
|
(** documentation for [Inner] *)
|
|
module Inner = struct
|
|
let v = ()
|
|
end
|
|
end
|
|
|
|
let _ = ();;
|
|
|
|
Outer.Inner.v
|
|
`);
|
|
|
|
const response = await queryCompletionItemResolve(
|
|
"Inner",
|
|
Types.Position.create(9, 10),
|
|
);
|
|
|
|
expect(response).toMatchInlineSnapshot(`
|
|
{
|
|
"documentation": "documentation for [Inner]",
|
|
"label": "Inner",
|
|
}
|
|
`);
|
|
});
|
|
});
|