vscode使用笔记

vscode 全称 Visual Studio Code

(1) 通用设置

(1.1) vs-code 设置语言

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

备注:打开命令面板 快捷键 mac Shift + Command + P(⇧⌘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"
}

(1.3) vscode更改图标

自定义您的VS Code图标
Icons and names usage guidelines

(2) vscode配置Java环境

VsCode搭建Java开发环境(Spring Boot项目创建、运行、调试)

安装如下两个主要扩展即可
在 Visual Studio Code 左侧打开扩展商店
Extension Pack for Java
Spring Boot Extension Pack

(3) vscode配置Go环境

1、安装go,在Vs code 扩展直接搜索Go,进行安装即可 或者 在 visualstudio-marketplace-go 下载go插件安装

2、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

(3.1) vscode中go debug

vscode-Go-debug

(3.2) 遇到的一些问题

(3.2.1) 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


(4) vscode配置thrift环境

VSCode 支持Thrift IDL 安装 Thrift Syntax Support 拆件

vscode-thrift插件


(5) 删除缓存

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

参考资料

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