无论我做什么,Vscode IntelliSense 都不适用于 C/C++

问题描述 投票:0回答:1

我无法让 Vscode 进行语法高亮或完成任何 C/C++ 代码。

  • 我使用的是最新的 Vscode(截至撰写本文时为 1.90.1)。
  • C/C++ 和 C/C++ 扩展包(最新、非内部版本)已安装并启用。
  • 我已经安装并运行了 clang。
  • 尝试遵循 Vscode 的官方文档https://code.visualstudio.com/docs/cpp/config-clang-mac

我创建了一个文件夹,使用

code /path/to/my/folder
打开它,有一个空的CPP文件。我正在逐行尝试文档所说的内容。我什至粘贴了文档中的确切代码,但它被识别为“纯文本”,并且没有完成或着色工作:

enter image description here

enter image description here

enter image description here

enter image description here

上面是我的 Vscode 环境,而 Microsoft 的文档很好地突出了语法,代码完成的 C/C++ 文件与我执行的步骤完全相同。在我的例子中,我什至没有在可供选择的语言列表中看到 C 或 C++,它被识别为“纯文本”。

这是我的

settings.json


{
    "workbench.startupEditor": "newUntitledFile",
    "explorer.confirmDelete": false,
    "workbench.colorTheme": "Monokai",
    "editor.codeLens": false,
    "git.autofetch": true,
    "git.enableSmartCommit": true,
    "explorer.confirmDragAndDrop": false,
    "git.confirmSync": false,
    "window.title": "${activeFolderShort}/${activeEditorShort} (${activeFolderLong})",
    "debug.console.fontSize": 10,
    "keyboard.dispatch": "keyCode",
    "editor.tabCompletion": "on",
    "prettier.tabWidth": 4,
    "editor.defaultFormatter": "dbaeumer.vscode-eslint",
    "editor.fastScrollSensitivity": 3,
    "typescript.tsserver.trace": "verbose",
    "C_Cpp.intelliSenseEngine": "default",
    "editor.tokenColorCustomizations": {
        "[Monokai]": {
            "keywords": "#ff4a5f",
            "functions": "#99ff88",
            "comments": "#80a090",
            "textMateRules": [
               
                {
                    "scope": "keyword.operator",
                    "settings": {
                        "foreground": "#ffaa66"
                    }
                },
                {
                    "scope": "entity.name.tag",
                    "settings": {
                        "foreground": "#ff3377",
                        "fontStyle": "bold"
                    }
                },
                {
                    "scope": "entity.other.attribute-name",
                    "settings": {
                        "foreground": "#44e855",
                    }
                }
            ]
        }
    },
    "workbench.colorCustomizations":{

        "[Monokai]": {
            "editorIndentGuide.background1": "#383838",
            "editor.background": "#20201e",
            "statusBar.background" : "#1A1A1A",
            "statusBar.noFolderBackground" : "#212121",
            "statusBar.debuggingBackground": "#263238",
        },
       
      },
      "task.slowProviderWarning": [
        "typescript"
      ],
      "update.mode": "manual",
      "typescript.updateImportsOnFileMove.enabled": "never",
      "javascript.updateImportsOnFileMove.enabled": "always",
    "editor.maxTokenizationLineLength": 1000,
      "terminal.integrated.fontSize": 9,
      "editor.fontSize": 8,
      "editor.minimap.renderCharacters": false,
      "editor.minimap.maxColumn": 80,
      "editor.minimap.enabled": false,
      "editor.gotoLocation.multipleDefinitions": "goto",
      "editor.gotoLocation.multipleDeclarations": "goto",
      "editor.gotoLocation.multipleImplementations": "goto",
      "editor.gotoLocation.multipleReferences": "goto",
      "editor.gotoLocation.multipleTypeDefinitions": "goto",
      "apc.activityBar": {
        "size": 42,
        "itemMargin": 2
      },
      "apc.sidebar.titlebar": {
        "fontSize": 10
      },
      "apc.header": {
        "fontSize": 10,
        "height": 24,
      },
      "apc.stylesheet": {
        ".explorer-viewlet .mac": "font-size: 11px",
        ".debug-viewlet .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench .debug-hover-widget .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench .debug-viewlet .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench .debug-hover-widget .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench.mac .debug-viewlet .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench.mac .debug-hover-widget .monaco-list-row .expression":
          "font-size: 10px !important",
        ".part.editor>.content .editor-group-container>.title .tabs-container>.tab, .tabs-and-actions-container": "height: 28px !important",
        ".monaco-icon-label": "font-size: 8pt",
        ".monaco-editor, .monaco-editor-background, .monaco-editor .inputarea.ime-input": "background-color: #1c1e1c"
      },
      "apc.listRow": {
        "height": 18
      },
      "customizeUI.fontSizeMap": {
          "window-title": "10px", // Window title font when using custom titlebar
          "tab-title": "11px",    // Used for editor tab titles
      },
      "customizeUI.listRowHeight": 18,
      "customizeUI.stylesheet": {
          ".explorer-viewlet .mac": "font-size: 11px",
          ".debug-viewlet .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench .debug-hover-widget .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench .debug-viewlet .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench .debug-hover-widget .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench.mac .debug-viewlet .monaco-list-row .expression, body.row-height-lte20 .monaco-workbench.mac .debug-hover-widget .monaco-list-row .expression":
            "font-size: 10px !important",
          ".part.editor>.content .editor-group-container>.title .tabs-container>.tab, .tabs-and-actions-container": "height: 28px !important",
          ".monaco-icon-label": "font-size: 8pt",
          ".monaco-editor, .monaco-editor-background, .monaco-editor .inputarea.ime-input": "background-color: #1c1e1c"
      },
      "emmet.showExpandedAbbreviation": "never",
      "terminal.integrated.lineHeight": 0.8,
      "color-highlight.languages": [
        "*"
      ],
    "editor.detectIndentation": false,
    "debug.javascript.suggestPrettyPrinting": false,
    "workbench.editor.decorations.badges": false,
    "explorer.decorations.badges": false,
    "react-native-tools.showUserTips": false,
    "editor.accessibilitySupport": "off",
    "react-native-tools.networkInspector.consoleLogsColorTheme": "Dark",
    "debug.console.wordWrap": false,
    "workbench.layoutControl.enabled": false,
    "editor.unicodeHighlight.allowedCharacters": {
        "‘": true,
        "’": true
    },
    "[typescriptreact]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[typescript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "solidity.validationDelay": 500,
    "debug.allowBreakpointsEverywhere": true,
    "workbench.settings.enableNaturalLanguageSearch": false,
    "explorer.compactFolders": false,
    "window.restoreWindows": "all",
    "editor.unicodeHighlight.includeStrings": false,
    "editor.codeActionsOnSave": {
        "source.organizeImports": "explicit"
    },
    "terminal.explorerKind": "external",
    "[css]": {
        "editor.defaultFormatter": "vscode.css-language-features"
    },
    "files.associations": {
        "*.css": "tailwindcss"
    },
    "eslint.runtime": "node",
    "eslint.format.enable": true,
    "workbench.editor.empty.hint": "hidden",
    "git.openRepositoryInParentFolders": "always",
    "solidity.telemetry": false,
    "cmake.showOptionsMovedNotification": false

}

请注意,

C_Cpp.intelliSenseEngine
设置不存在,但仍然无法正常工作,我在尝试寻找解决方案时添加了它,但似乎没有什么区别。

我还尝试禁用除 C/C++ 之外的所有扩展(并且,在另一个实例中,除了 C/C++ 之外,还有 C/C++ 扩展包)并重新启动 Vscode,但没有任何改变。

我做错了什么?

c++ c visual-studio-code intellisense
1个回答
1
投票

我通过删除我的

~/Library/Application Support/Code
~/.vscode/extensions
目录解决了这个问题(我首先单独尝试了后者但没有成功,然后我也删除了前者)。我不知道是什么导致了这个问题,但我从那里备份了我的
settings.json
,删除了所有内容,重新启动了 Vscode,将
settings.json
放回去,重新启动了 Vscode,安装了 C/C++ 扩展(因为所有扩展也都被删除了) ,问题得到解决。我现在可以在语言列表中看到 C++,并且 IntelliSense 运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.