本文整理匯總了TypeScript中vscode-languageserver-types.TextDocumentItem類的典型用法代碼示例。如果您正苦於以下問題:TypeScript TextDocumentItem類的具體用法?TypeScript TextDocumentItem怎麽用?TypeScript TextDocumentItem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TextDocumentItem類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('TextDocumentItem', () => {
let uri = 'file:///folder/file.txt';
let item = TextDocumentItem.create(uri, 'pain-text', 9, 'content');
strictEqual(item.uri, uri);
strictEqual(item.languageId, 'pain-text');
strictEqual(item.version, 9);
strictEqual(item.text, 'content');
ok(TextDocumentItem.is(item));
});
示例2: it
it("updates in at the start of the line", async () => {
let languageServer = await LanguageServer.startAndInitialize();
await languageServer.sendNotification("textDocument/didOpen", {
textDocument: Types.TextDocumentItem.create(
"file:///test-document.txt",
"txt",
0,
"let x = 1;\n\nlet y = 2;"
)
});
expect(await getDoc(languageServer)).toEqual("let x = 1;\n\nlet y = 2;");
await languageServer.sendNotification("textDocument/didChange", {
textDocument: Types.VersionedTextDocumentIdentifier.create(
"file:///test-document.txt",
1
),
contentChanges: [
{
range: {
start: { line: 1, character: 0 },
end: { line: 1, character: 0 }
},
rangeLength: 0,
text: "s"
}
]
});
expect(await getDoc(languageServer)).toEqual("let x = 1;\ns\nlet y = 2;");
languageServer = await LanguageServer.startAndInitialize();
});
示例3: it
it("returns type inferred under cursor with documentation", async () => {
languageServer = await LanguageServer.startAndInitialize({
textDocument: {
hover: {
dynamicRegistration: true,
contentFormat: ["markdown", "plaintext"]
}
}
});
await languageServer.sendNotification("textDocument/didOpen", {
textDocument: Types.TextDocumentItem.create(
"file:///test.ml",
"txt",
0,
"(** This function has a nice documentation *)\nlet id x = x\n"
)
});
let result = await languageServer.sendRequest("textDocument/hover", {
textDocument: Types.TextDocumentIdentifier.create("file:///test.ml"),
position: Types.Position.create(1, 4)
});
expect(result).toMatchObject({
contents: {
kind: "markdown",
value: "```ocaml\n'a -> 'a\n(** This function has a nice documentation *)\n```" }
});
});
示例4: openDocument
async function openDocument(source) {
await languageServer.sendNotification("textDocument/didOpen", {
textDocument: Types.TextDocumentItem.create(
"file:///test.ml",
"txt",
0,
source
)
});
}