Пишу расширение(Language Server Protocol) для VS Code для поддержки проприетарного языка программирования. Соответственно расширение состоит из двух частей - серверной и клиентской.
В серверной части в процессе парсинга исходника получаю имя файла "fileName.ext" и его как-то надо найти и получить его содержимое. В клиентской части нашел
workspace.findFiles(name);
но в серверной части это не работает. Подскажите как можно осуществить поиск файла и получить его содержимое, зная его имя в серверной части.
0
1 ответ
0
сам спросил, сам ответил. Тот же ответ на англ версии сайта.
On server side:
export function GetFileRequest(nameInter:string) {
connection.sendRequest("getFile", nameInter).then( (body : string) => {
if (body != undefined && body.length) pushImports(body);
});
}
on client side: in function activate(context: ExtensionContext) after client.start();
client.onReady().then(() => {
client.onRequest("getFile", (nameInter : string) : Promise<string> => { return getFile(nameInter); } );
});
and async function on client side:
async function getFile(name):Promise<string>{
let uri:Uri = undefined;
let text:string = undefined;
await workspace.findFiles(name, null, 1).then((value)=> {
if (value.length) {
uri=value[0];
}
});
if (uri!=undefined) {
let textDocument;
await workspace.openTextDocument(uri).then((value)=>textDocument = value);
text = textDocument.getText();
}
return text;
}
This code will return a text from file to server side.