[英]How do i connect LSP to Webview2 monaco editor
我這里有https://github.com/arnoson/monaco-lua-example ,這是一個將語言服務器連接到 monaco 編輯器的示例(我的是專門由 webview2 托管的。)
https://github.com/NightrainsRbx/RobloxLsp是具有我需要的功能的語言服務器分支,如果您使用上面的示例,它會顯示“需要升級”,所以作為初學者,在這里做的並不多。
我也知道 monaco.languages.register 和 registerlanguageserver 以及類似的東西,但我不確定我將如何使用它。
我試過了,這不是你看到的一些好代碼,而且效果很差,當你這樣做並在 monaco 編輯器中輸入一些故意產生錯誤的東西時,它沒有響應。
string lspPath = Path.Combine(Environment.CurrentDirectory, "lsp", "server");
string exePath = Path.Combine(lspPath, "lua-language-server.exe");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = exePath;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardOutput = true;
string lspPath2 = Path.Combine(Environment.CurrentDirectory, "lsp");
string exePath2 = Path.Combine(lspPath2, "lsp-ws-proxy.exe");
ProcessStartInfo startInfo2 = new ProcessStartInfo();
startInfo2.CreateNoWindow = false;
startInfo2.UseShellExecute = false;
startInfo2.FileName = exePath2;
startInfo2.WindowStyle = ProcessWindowStyle.Hidden;
startInfo2.RedirectStandardOutput = true;
Process process2 = Process.Start(startInfo2);
using (Process process = Process.Start(startInfo))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Debug.WriteLine(result);
}
}
webView.Source = new Uri(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, @"Rosploco\rosploco.html"));
// Inject a script into the WebView2 to register the Lua language server
string script = "monaco.languages.register({ id: 'roblox-lua' }).then(function () {" +
" monaco.languages.setLanguageConfiguration('lua', {" +
" comments: {" +
" lineComment: '--'," +
" blockComment: ['--[[', ']]']" +
" }," +
" brackets: [[" +
" ['{','}']," +
" ['[',']']," +
" ['(',')']" +
" ]]," +
" autoClosingPairs: [" +
" { open: '{', close: '}' }," +
" { open: '[', close: ']' }," +
" { open: '(', close: ')' }," +
" { open: '\"', close: '\"' }," +
" { open: '\'', close: '\'' }" +
" ]," +
" surroundingPairs: [" +
" { open: '{', close: '}' }," +
" { open: '[', close: ']' }," +
" { open: '(', close: ')' }," +
" { open: '\"', close: '\"' }," +
" { open: '\'', close: '\'' }" +
" ]," +
" folding: {" +
" markers: {" +
" start: new RegExp('^\\s*//\\s*#region\\b')," +
" end: new RegExp('^\\s*//\\s*#endregion\\b')" +
" }" +
" }" +
" });" +
"});";
webView.ExecuteScriptAsync(script);
Update
我必須執行npm run dev
並導航到 localhost:3000,現在它可以正常工作並且已正確連接,但我仍然需要 webview2 才能連接到它。
沒關系,我必須在 monaco-lua-example 中執行npm run dev
並導航到 localhost:3000。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.