Visual Studio Code启用建议代码JavaScript,就像在WebStorm中一样

时间:2018-06-07 21:18:24

标签: javascript visual-studio-code webstorm

我正在寻找一个解决方案如何启用JavaScript代码的所有建议,例如我在VSC和WebStorm中编写相同的代码:

enter image description here

在WebStorm中,我的所有建议都与单词remov匹配,但在VSC中我有信息:No suggestions.

我尝试使用这个问题的答案,但没有任何作用:

How to enable Intellisense for JavaScript in Visual Studio Code

VSCode intelliSense autocomplete for javascript

VS Code autocompletion base on word in file

我有版本VSC 1.24.0

我的settings.json文件:

{
    "php.validate.executablePath": "C:\\php7\\php.exe",
    "workbench.iconTheme": "vscode-icons",
    "files.associations": {
        "*.ejs": "html",
        "*.js": "javascript"
    },
    "css.fileExtensions": [
        "css",
        "scss"
    ],
    "sublimeTextKeymap.promptV3Features": true,
    "editor.multiCursorModifier": "ctrlCmd",
    "editor.snippetSuggestions": "top",
    "editor.formatOnPaste": true,
    "editor.wordWrap": "on",
    "window.menuBarVisibility": "toggle",
    "window.zoomLevel": 0,
    "workbench.colorTheme": "Afterglow",
    "editor.fontSize": 14,
    "editor.renderIndentGuides": false,
    "files.autoSave": "onFocusChange",
    "vsicons.dontShowNewVersionMessage": true,
    "editor.quickSuggestions": {
        "other": true,
        "comments": true,
        "strings": true
    },
    "editor.quickSuggestionsDelay": 1,
    "editor.suggestOnTriggerCharacters": true,
    "editor.wordBasedSuggestions": true,
    "editor.parameterHints": true
}

编辑:

我使用的所有代码:

document.addEventListener("DOMContentLoaded", function () {


    function Calendar(input) {
        this.now = new Date();
        this.day = this.now.getDate();
        this.month = this.now.getMonth();
        this.year = this.now.getFullYear();

        this.input = input; 
        this.divCnt = null; 
        this.divHeader = null; 
        this.divTable = null; 
        this.divDateText = null; 
        this.divButtons = null; 


        this.init = function() {

            this.divCnt = document.createElement('div');
            this.divCnt.classList.add('calendar');

            this.divButtons = document.createElement('div');
            this.divButtons.className = "calendar-prev-next";

            this.divDateText = document.createElement('div');
            this.divDateText.className = 'date-name';

            this.divHeader = document.createElement('div');
            this.divHeader.classList.add('calendar-header');

            this.divHeader.appendChild(this.divButtons);
            this.divHeader.appendChild(this.divDateText);

            this.divHeader.appendChild();
        };

    }

});

1 个答案:

答案 0 :(得分:0)

VS Code的智能感知无法推断divCnt的类型,因为它未在构造函数中分配。您可以通过在构造函数中指定值或使用jsdocs来启用正确的智能感知:

function Calendar(input) {
    this.divCnt = /** @type {HTMLDivElement} */ (null);
}

根本原因是https://github.com/Microsoft/TypeScript/issues/10868