繁体   English   中英

我如何将 LSP 连接到 Webview2 摩纳哥编辑器

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM