Q: Go IntelliSense with VS Code and VirtualBox

xuanbao · · 550 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m using VisualStudio Code on macOS for writing code in go and one of the features I love the most is IntelliSense, which properly displays code-completion suggestions and documentation when needed, using this language-support extension: <a href="https://marketplace.visualstudio.com/items?itemName=lukehoban.Go" rel="nofollow">https://marketplace.visualstudio.com/items?itemName=lukehoban.Go</a><br/> Question: I now have to use a VM (inside VirtualBox for Mac) in order to be able to use a couple of os-specific go-packages (Most notably: <a href="https://github.com/rgbkrk/libvirt-go" rel="nofollow">https://github.com/rgbkrk/libvirt-go</a>) - how can I still get proper IntelliSense / Code Completion for this package inside of VS Code running on the host OS? The packages <em>have</em> to be installed on the guest VM because <em>they won&#39;t install on the host OS</em>. (That is because macOS is missing the libvirt-dev package&#39;s headers that this go-package requires)<br/> Any answers / suggestions are much appreciated :)</p> <hr/>**评论:**<br/><br/>zxo0oxz: <pre><p>Here&#39;s a couple ideas here. Your intellisense plugin is based off gocode. gocode runs as a server that the client communicates through a unix socket for. Run gocode on the guest vm and map the socket somewhere on the host os. Point the intellisense/host os gocode client at the file handle and see if it works.</p> <p>Alternatively, you could try copying the GOPATH from the guest os to the host os and see if gocode can still read the symbols.</p> <p>Last idea: this gocode setting looks like it may be useful</p> <blockquote> <p>lib-path</p> <p>A string option. Allows you to add search paths for packages. By default, gocode only searches $GOPATH/pkg/$GOOS<em>$GOARCH and $GOROOT/pkg/$GOOS</em>$GOARCH in terms of previously existed environment variables. Also you can specify multiple paths using &#39;:&#39; (colon) as a separator (on Windows use semicolon &#39;;&#39;). The paths specified by lib-path are prepended to the default ones.</p> </blockquote></pre>F41LUR3: <pre><p>I&#39;m a bit curious as to why it would matter if the package you&#39;re writing code with doesn&#39;t have the headers for your OS. the Intellisense/autocomplete (minus compiler errors of course) built into vscode-go is based off of go tools analyzing the source of the packages. While you may be able to compile, the intellisense/autocomplete should work since the source is there, right?</p></pre>thelamacmdr: <pre><p>Is there any particular reason why you can&#39;t use VSCode within the VM itself?</p></pre>unausstehlich: <pre><p>Because running the editor inside the VM gets sluggish and slow really quickly on my machine, plus switching between VM os and guest OS is a pain</p></pre>mgutz: <pre><p>Docker is another option. Map a volume to your Mac work directory. Run your go code inside container. Edit on your mac.</p> <p>edit: never mind. you still need compilable source on your mac for that to work</p></pre>paulsh94: <pre><p>I would suggest you have a look into Vagrant. You can set up the VM through it and have files in your project synced automatically. I&#39;m assuming it just uses some sort of daemon to watch the files and sync them (i.e. rsync) so you could do that manually, but Vagrant is really cool.</p> <p>One of the most common workflows is to develop code on your machine and let the build and test be in the VM. Also, it can use AWS or other providers instead of VirtualBox. <a href="https://www.vagrantup.com/" rel="nofollow">https://www.vagrantup.com/</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

550 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传