VSCode 扩展不会更新语言服务器中的语义模型
我在 eclipse 中创建了一个 Xtext 语法和语言服务器,这是构建并添加到 vscode 扩展中的。我已经实现了以下代码来启动语言服务器。
import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
Trace,
TransportKind
} from 'vscode-languageclient/node'; // Use this dependency for version >= 7.0.0
export function activate(context: ExtensionContext) {
const executable = 'prototype.dsl.ide.bat';
const languageServerPath = path.join('server', 'bin', executable);
const serverLauncher = context.asAbsolutePath(languageServerPath);
const serverOptions: ServerOptions = {
run: {
command: serverLauncher,
args: ['-trace', '-log', 'debug'],
transport: TransportKind.ipc
},
debug: {
command: serverLauncher,
args: ['-trace', '-log', 'debug'],
transport: TransportKind.ipc
}
};
const config = workspace.getConfiguration();
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'tst' }],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/*.*,**/*.tst')
},
initializationOptions: {
config
}
};
const languageClient = new LanguageClient('lspLanguageClient', 'Language Server', serverOptions, clientOptions);
languageClient.start();
languageClient.trace = Trace.Verbose;
let disposable = languageClient.start();
context.subscriptions.push(disposable);
}
在 vscode 中测试实现可以正常工作,并且可以检测到语法规则。
我遇到的问题是,在 vscode 中保存对文档的更改仅第一次反映在语言服务器中,所有后续修改和保存都不会反映在语言服务器中。
I created an Xtext grammar and Language server in eclipse, this was built and added to a vscode extension. I have implemented the below code to start up the language server.
import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
Trace,
TransportKind
} from 'vscode-languageclient/node'; // Use this dependency for version >= 7.0.0
export function activate(context: ExtensionContext) {
const executable = 'prototype.dsl.ide.bat';
const languageServerPath = path.join('server', 'bin', executable);
const serverLauncher = context.asAbsolutePath(languageServerPath);
const serverOptions: ServerOptions = {
run: {
command: serverLauncher,
args: ['-trace', '-log', 'debug'],
transport: TransportKind.ipc
},
debug: {
command: serverLauncher,
args: ['-trace', '-log', 'debug'],
transport: TransportKind.ipc
}
};
const config = workspace.getConfiguration();
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'tst' }],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/*.*,**/*.tst')
},
initializationOptions: {
config
}
};
const languageClient = new LanguageClient('lspLanguageClient', 'Language Server', serverOptions, clientOptions);
languageClient.start();
languageClient.trace = Trace.Verbose;
let disposable = languageClient.start();
context.subscriptions.push(disposable);
}
Testing the implementation in vscode works and the grammar rules are detected.
The issue I am having is that in vscode on save the changes to the document only reflect in the language server the first time, all subsequent modifications and saves are not reflected in the language server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法解决了我的问题,服务器正在使用以下方法访问文档资源。
上面的代码在 eclipse 中测试时有效,但在 vscode 扩展中使用时无效。
我更改了上面的代码以使用以下代码获取资源,它在 eclipse 和 vscode 扩展中都有效。
I managed to solve my issue, the server was accessing the document resource using the below method.
The above code works when testing in eclipse, but not when used in a a vscode extension.
I changed the above code to get the resource using the following and it worked in both eclipse and vscode extension.