VSCode 配置记录

519 阅读1分钟

字体推荐:安装 vscode: JetBrains Mono

123

如何通过vscode实现像goland界面 configurations 添加执行配置文件和-tags来进行单元单测? image.png

方法如下: 1.创建launch.json文件

image.png

文件后面加上args参数

"args": [
     "-c=~/conf/conf.ini"
]

其他配置项

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch", // 调试配置的名称
            "type": "go", // 调试类型,对于Go语言通常是"go"
            "request": "launch", // 请求类型,通常是"launch""attach"
            "program": "${fileDirname}", // 要调试的程序的路径
            "dlvLoadConfig": {
                "followPointers": true,
                "maxVariableRecurse": 1,
                "maxStringLen": 2048, // 设置字符串最大长度为2048
                "maxArrayValues": 64,
                "maxStructFields": -1
            },
            "args": [
                "-env=test", // 传递给程序的参数
            ],
            "mode": "debug",
        }
    ]
}

2.vscode setting.js配置

{
    "[rust]": {
        "editor.defaultFormatter": "matklad.rust-analyzer",
        "rust-analyzer.enableCargoWatchOnStartup": "true", // 打开项目时自动开启 cargo watch
        "rust-analyzer.highlightingOn": true, // 覆盖内建语法高亮
        "rust-analyzer.lruCapacity": 1000, // 分析器最大缓存深度
    },
    "workbench.preferredLightColorTheme": "Visual Studio Dark",
    "emmet.excludeLanguages": [
        "markdown"
    ],
    "editor.formatOnType": true,
    "editor.formatOnSave": true,
    "go.autocompleteUnimportedPackages": true,
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.inferGopath": true,
    "go.gopath": "~/apps/works/go",
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "editor.fontSize": 15,
    "terminal.integrated.fontSize": 16,
    "terminal.integrated.fontFamily": "monospace",
    "go.addTags": {
        "tags": "zookeeper"
    },
    "python.defaultInterpreterPath": "/usr/bin/python3",
    "go.toolsManagement.autoUpdate": true,
    // todo 高亮
    "todohighlight.isEnable": true,
    "todohighlight.isCaseSensitive": true,
    "todohighlight.keywords": [
        {
            "text": "todo",
            "color": "red",
            "border": "1px solid red",
            "borderRadius": "2px", //NOTE: using borderRadius along with `border` or you will see nothing change
            "backgroundColor": "rgba(0,0,0,.2)",
        },
        {
            "text": "TODO",
            "color": "red",
            "border": "1px solid red",
            "borderRadius": "2px", //NOTE: using borderRadius along with `border` or you will see nothing change
            "backgroundColor": "rgba(0,0,0,.2)",
            //other styling properties goes here ... 
        }
    ],
    "todohighlight.include": [
        "**/*.js",
        "**/*.html",
        "**/*.php",
        "**/*.go",
        "**/*.css",
    ],
    "python.insidersChannel": "weekly",
    "git.autofetch": true,
    "files.associations": {
        "*.cjson": "jsonc",
        "*.wxss": "css",
        "*.wxs": "javascript"
    },
    "emmet.includeLanguages": {
        "wxml": "html"
    },
    "minapp-vscode.disableAutoConfig": true,
    "pasteImage.path": "${projectRoot}",
    "aws.telemetry": false,
    "codeium.enableConfig": {
        "*": true,
        "markdown": true
    },
    "editor.inlineSuggest.enabled": true,
    "github.copilot.enable": {
        "*": true,
        "plaintext": false,
        "markdown": true,
        "scminput": false
    },
    "codeium.enableSearch": true,
    "workbench.colorTheme": "Darcula",
    "editor.fontWeight": "normal",
    "go.buildTags": "\"zookeeper\"",
    "go.testFlags": [
        "-v",
        "-count=1",
    ],
    "projectManager.sortList": "Saved",
    "go.docsTool": "guru",
    "editor.codeActionsOnSave": {},
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        }, // Optional: Disable snippets, as they conflict with completion ranking.    "editor.snippetSuggestions": "none", 
    },
    "[go.mod]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        },
    },
    "go.trace.server": "verbose",
    "gopls": {
        // Add parameter placeholders when completing a function. 
        "usePlaceholders": false,
        // If true, enable additional analyses with staticcheck. 
        // Warning: This will significantly increase memory usage.   "staticcheck": false, 
    },
    "go.languageServerFlags": [
        "-remote=auto",
        "-logfile=auto",
        "-debug=:0",
        "-rpc.trace",
    ],
}

调试代码变量时候,字符串显示more更多,没有显示全咋办?

image.png

通过设置该参数解决 "maxStringLen": 1024, // 设置字符串最大长度为1024

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch", // 调试配置的名称
            "type": "go", // 调试类型,对于Go语言通常是"go"
            "request": "launch", // 请求类型,通常是"launch""attach"
            "program": "${fileDirname}", // 要调试的程序的路径
            "dlvLoadConfig": {
                "followPointers": true,
                "maxVariableRecurse": 1,
                "maxStringLen": 1024, // 设置字符串最大长度为1024
                "maxArrayValues": 64,
                "maxStructFields": -1
            }
        }
    ]
}