Quantcast
Channel: Vimタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 5695

TinyGo + `VSCode or Vim (もしくはそれ以外の LSP 対応エディタ)` で gopls 連携する方法

$
0
0

TinyGo 0.15 がリリースされて、 gopls との連携が簡単になりました。
逆に言うと今までは 設定がそれなりに面倒でした。

このページでは、 TinyGo 0.15 以降での gopls 連携の方法を VSCodeおよび Vim (もしくはそれ以外の LSP 対応エディタ)に対して記載します。

注意)
以降、 wioterminalというターゲットを例として記載します。
適宜、使いたいターゲットに読み替えてください。

VSCode

まずは、 VSCode の Extensions > TinyGo 0.2.0をインストールします。

Screenshot from 2020-09-23 21-28-47.png

次に tinygo のソースコード (*.go) を開いている状態で Command palette > TinyGo targetsを実行します。

Screenshot from 2020-09-23 21-22-51.png

pick a target...と表示されるので wioterminalを選択します。

Screenshot from 2020-09-23 21-21-01.png

Reload を促されるので Reload します。

Screenshot from 2020-09-23 21-21-46.png

この時点で machine.LEDの定義が表示されていれば gols 連携は OK です。

Screenshot from 2020-09-23 21-23-24.png

ターゲットを切り替えたい場合は、 Command palette > TinyGo targetsを再度実行してください。

Vim (もしくはそれ以外の LSP 対応エディタ)

まずは tinygo-editをインストールします。
以下から実行体を DL し PATH の通った場所に置いてください。

もしくは、以下のコマンドでもインストールすることが出来ます。

$ go get github.com/sago35/tinygo-edit

その後、以下をソースコードのあるディレクトリで実行します。
エディタに合わせて少し設定が必要です。

# Vim
$ tinygo-edit --target xiao --editor vim --wait

# gVim
$ tinygo-edit --target xiao --editor gvim

# VSCode (VSCode は上記の TinyGo extensions を使ったほうが良い)
$ tinygo-edit --target xiao --editor code

この時点で machine.LEDの定義が表示されていれば gopls 連携は」 OK です。

Screenshot from 2020-09-23 21-27-16.png

なお、この方法で開いた vim から立ち上げた terminal では tinygo buildtinygo flashが出来ません。
環境変数 GOROOT が設定されているためです。

Screenshot from 2020-09-23 21-32-31.png

以下のようにして GOROOT の設定を削除すると tinygo build等を実施出来るようになります。

# windows / cmd.exe の場合
$ set GOROOT=

# bash の場合
$ unset GOROOT

Screenshot from 2020-09-23 21-35-29.png

ターゲットを切り替えたい場合は、 tinygo-editを再度実行してください。

Link


Viewing all articles
Browse latest Browse all 5695

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>