vscode使用笔记

vscode 全称 Visual Studio Code

(1) 常用设置

(1.1) vs-code 设置语言

打开命令面板 ,输入 configure display language,设置语言为 zh-cn

备注:打开命令面板快捷键 mac Shift + Command + P Windows Ctrl + Shift + p

(1.2) vs-code 设置背景豆沙绿

修改配置文件 ~/Library/Application Support/Code/User/settings.json
"editor.background" 设置成 "#C7EDCC",具体如下:

{
    "workbench.colorTheme": "Default Light+",
    "workbench.colorCustomizations": {
        "editor.background": "#C7EDCC"
        //设置用户选中代码段的颜色 
        //"editor.selectionBackground": "#2f00ff",
        //搜索匹配的背景色
        //"editor.findMatchBackground": "#ff0000",
        //"editor.findMatchHighlightBackground": "#ff00ff",
        //"editor.findRangeHighlightBackground": "#ff9900"
    
    },
    "editor.fontSize": 16,
    "window.openFoldersInNewWindow": "off",
    "window.openWithoutArgumentsInNewWindow": "on",
    "editor.largeFileOptimizations": false,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.configuration.checkProjectSettingsExclusions": false,
    "extensions.autoUpdate": false,
    "window.zoomLevel": 0,
    "update.mode": "none"
}

vscode运行go代码

vscode配置go环境

1、安装go

2、在Vs code 扩展直接搜索Go,进行安装即可

3、Vs code打开输入:Command+Shift+P, 在弹出框内输入:Go:install/update Tools,工具全选,进行安装。

Tools environment: GOPATH=/Users/weikeqin/gopath
Installing 9 tools at /Users/weikeqin/gopath/bin in module mode.
  gopkgs
  go-outline
  gotests
  gomodifytags
  impl
  goplay
  dlv
  golint
  gopls

Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs (/Users/weikeqin/gopath/bin/gopkgs) SUCCEEDED
Installing github.com/ramya-rao-a/go-outline (/Users/weikeqin/gopath/bin/go-outline) SUCCEEDED
Installing github.com/cweill/gotests/... (/Users/weikeqin/gopath/bin/gotests) SUCCEEDED
Installing github.com/fatih/gomodifytags (/Users/weikeqin/gopath/bin/gomodifytags) SUCCEEDED
Installing github.com/josharian/impl (/Users/weikeqin/gopath/bin/impl) SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay (/Users/weikeqin/gopath/bin/goplay) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv (/Users/weikeqin/gopath/bin/dlv) SUCCEEDED
Installing golang.org/x/lint/golint (/Users/weikeqin/gopath/bin/golint) SUCCEEDED
Installing golang.org/x/tools/gopls (/Users/weikeqin/gopath/bin/gopls) SUCCEEDED

All tools successfully installed. You are ready to Go :).

Vs code配置Go语言环境-Mac

vscode中go debug

tempCodeRunnerFile.go:1:1: expected ‘package’, found main

[Running] go run "/Users/weikeqin/WorkSpaces/golang/go-debug/tempCodeRunnerFile.go"
tempCodeRunnerFile.go:1:1: expected 'package', found main

[Done] exited with code=1 in 0.038 seconds

在写了一个文件后,选中运行,一直提示 tempCodeRunnerFile.go:1:1: expected ‘package’, found main
后来发现是VSCode生成tempcoderunnerfile的问题

解决办法
1、在setting.json里添加配置
2、在设置中搜索ignoreSelection并勾选Whether to ignore selection to always run entire file.

{
    "code-runner.ignoreSelection": true
}

How to avoid tempCodeRunnerFile.go appear in the project
VSCode生成tempcoderunnerfile

删除缓存

rm -rf ~/Library/Application\ Support/Code/Cache/*
rm -rf ~/Library/Application\ Support/Code/CachedData/*

References

[1] vscode-docs
[2] clear-your-visual-studio-code-cache-on-a-mac
[3] 自定义您的VS Code图标