简体   繁体   English

为 monaco-editor 添加 vue js 语言支持

[英]Add vue js language support to monaco-editor

I've been trying to add vuejs language support to monaco editor, but all my attempts have failed so far.我一直在尝试向 monaco 编辑器添加 vuejs 语言支持,但到目前为止我所有的尝试都失败了。 I've tried monaco-vue plugin for editor for but it doesnt seem to work either.我已经尝试过用于编辑器的monaco-vue插件,但它似乎也不起作用。

The end result that I would want to achieve is to provide completions just as codesandbox.io if not as good as vetur (vuejs plugin for vscode).我想要实现的最终结果是提供与codesandbox.io一样的完成,如果不如vetur (vuejs插件vscode)。

Any kind of help would be appreciate.任何形式的帮助将不胜感激。 Thanks in advance.提前致谢。

Monaco-vue, to my knowledge, simply enables you to easily render the Monaco Editor into your Vue app by way of a Vue component.据我所知,Monaco-vue 只是让您能够通过 Vue 组件轻松地将 Monaco Editor 渲染到您的 Vue 应用程序中。 Vue language support within the editor requires that you hook up the editor to a Language Server Protocol (LSP)-compliant service.编辑器中的 Vue 语言支持要求您将编辑器连接到符合语言服务器协议 (LSP) 的服务。 I believe Vetur is an LSP implementation - though I have not yet attempted to connect my Monaco editor to it as of yet.我相信 Vetur 是一个 LSP 实现——尽管我还没有尝试将我的 Monaco 编辑器连接到它。 The Vetur LSP project seems to have decent documentation: https://github.com/vuejs/vetur/tree/master/server Vetur LSP 项目似乎有不错的文档: https ://github.com/vuejs/vetur/tree/master/server

For an overview of integrating LSP into a Monaco editor, see this: https://typefox.io/teaching-the-language-server-protocol-to-microsofts-monaco-editor有关将 LSP 集成到 Monaco 编辑器的概述,请参阅: https ://typefox.io/teaching-the-language-server-protocol-to-microsofts-monaco-editor

...and a link to a module that helps with this (also from Typefox): https://github.com/TypeFox/monaco-languageclient ...以及一个有助于解决此问题的模块的链接(也来自 Typefox): https ://github.com/TypeFox/monaco-languageclient

Beware that, as of my last visit to that project, it does not work with the very latest version of Monaco - though I haven't lost any features of note by staying back at version 14.xx.请注意,在我上次访问该项目时,它不适用于最新版本的 Monaco - 尽管我没有因为回到 14.xx 版本而失去任何值得注意的功能。

Also, I couldn't get Monaco Vue to work for me.此外,我无法让 Monaco Vue 为我工作。 It isn't hard to embed via the mounted lifecycle hook that renders the editor to the DOM on the mounted hook, like this:通过将编辑器渲染到安装钩子上的 DOM 的安装生命周期钩子嵌入并不难,如下所示:


  mounted: function () {
    this.editor = monaco.editor.create(document.getElementById('container'), {
      value: 'this is code',
      automaticLayout: true
    })
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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