VSCode Python Intellisense Not Working Properly - visual-studio-code

Python autocomplete in VSCode is messing up my code
Here is my system:
If I use Pylance, Intellisense does not work properly
and if I use Jedi, Intellisense does not work properly
When I press enter, my code is completely borked. This is just one example and has been frustrating the heck out of me!
Below is my settings.json file:
{
"AREPL.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"dicom.alwaysShowMenu": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.insertSpaces": false,
"editor.rulers": [
90
],
"editor.suggestSelection": "first",
"explorer.compactFolders": false,
"explorer.confirmDragAndDrop": false,
"files.exclude": {
"**/.git": false
},
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"git-graph.defaultColumnVisibility": {
"Author": false,
"Commit": true,
"Date": false
},
"git-graph.referenceLabels.alignment": "Branches (aligned to the graph) & Tags (on the right)",
"glassit.alpha": 255,
"json.format.enable": true,
"mypy.dmypyExecutable": "${workspaceFolder}\\.venv\\Scripts\\dmypy.exe",
"mypy.runUsingActiveInterpreter": true,
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"python.formatting.blackArgs": [
"--line-length",
"90"
],
"python.formatting.provider": "black",
"python.languageServer": "Jedi",
"python.linting.enabled": true,
// "python.linting.flake8Args": [
// "--line-length",
// "90"
// ],
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "${workspaceFolder}\\.venv\\Scripts\\mypy.exe",
// "python.linting.pylintArgs": [
// "--generate-members"
// ],
// "python.linting.pylintEnabled": true,
"python.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"python.terminal.activateEnvironment": true,
"python.testing.pytestArgs": [
"${workspaceFolder}\\tests"
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": true,
"python.venvPath": ".venv",
"restructuredtext.builtDocumentationPath": "${workspaceFolder}\\docs\\build\\html",
"restructuredtext.confPath": "{workspaceFolder}\\docs\\source",
"restructuredtext.languageserver.disabled": true,
"restructuredtext.sphinxBuildPath": "${workspaceFolder}\\.venv\\Scripts\\sphinx-build.exe",
"screencastMode.keyboardOverlayTimeout": 1500,
"screencastMode.mouseIndicatorSize": 20,
"screencastMode.onlyKeyboardShortcuts": true,
"screencastMode.verticalOffset": 0,
"security.workspace.trust.untrustedFiles": "open",
"shellcheck.customargs": [
"-x"
],
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.fontFamily": "CaskaydiaCove Nerd Font Mono",
"terminal.integrated.tabs.enabled": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"update.enableWindowsBackgroundUpdates": false,
"vsicons.dontShowNewVersionMessage": true,
"workbench.colorTheme": "Predawn",
"workbench.editor.enablePreview": true,
"workbench.editorAssociations": {
"*.dcm": "default",
"*.ipynb": "jupyter-notebook",
"*.tiff": "tiff.preview",
"git-rebase-todo": "default"
},
"workbench.iconTheme": "material-icon-theme",
"workbench.settings.editor": "json",
"workbench.settings.openDefaultSettings": true,
"workbench.settings.useSplitJSON": true,
"workbench.startupEditor": "newUntitledFile"
}
Why is this happening and how can I fix my Intellisense?
Update:
Removing "editor.suggestSelection": "first" helped, but I still get errors:

Adding the following to my settings.json makes Intellisense work as expected:
"editor.acceptSuggestionOnEnter": "off",
"editor.tabCompletion": "on"
Why the defaults are "on" and "off", respectively, I will never know. Everyone expects to press tab if you want to use the suggestion (like in bash terminal), and no one wants the autocomplete to complete blindly upon hitting enter.

Related

Unable to write in VScode settings

It seems i am unable to write in any new setting as my settings.json has an error of some kind. I have tried removing certain duplicate lines and also adding new brackets to see if it would assist with the issue but so far i have not been able to figure out the problem. Here is what i have managed to do so far,
{
"editor.suggest.localityBonus": true,
"editor.suggest.statusBar.visible": true,
"editor.quickSuggestions": null,
"editor.snippetSuggestions": "bottom",
"files.autoSave": "afterDelay",
"liveServer.settings.donotShowInfoMsg": true,
"workbench.iconTheme": "material-icon-theme",
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true,
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"workbench.colorTheme": "Monokai Pro (Filter Spectrum)",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"emmet.preferences": {
},
"workbench.editorAssociations": {
"*.ipynb": "jupyter.notebook.ipynb"
},
"mssql.connections": [
{
"server": "{{put-server-name-here}}",
"database": "{{put-database-name-here}}",
"user": "{{put-username-here}}",
"password": "{{put-password-here}}"
}
],
"security.workspace.trust.untrustedFiles": "open",
"editor.fontSize": 18,
"editor.tabSize": 3,
"editor.guides.bracketPairs": true
{
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs":"active"
}
}
I get an error saying "expected comma Ln33 col 3" and "end of file expected at Ln 37"
Change from:
"editor.guides.bracketPairs": true
{
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs":"active"
}
to
"editor.guides.bracketPairs": true, // choose true/false/active
// { // gat rid of this {
"editor.bracketPairColorization.enabled": true,
// "editor.guides.bracketPairs":"active"
// } // get rid of this }

VS code indentation mode changes from spaces to tab

I am using VS code with a number of extensions, including pylance , editorconfig, prettier, . No matter how many times I change the insertSpaces to true for the different languages or any indentation related settings to spaces mode, at some point (sometimes after a couple of minutes of usage, sometimes after reopening VS code) the tab key starts indenting with tab. I notice this mostly by pressing enter. How can I figure out which extension is doing overriding the spaces indentation mode? I don't want to go through the exercise of testing them one by one. Here's my settings.json that I have pruned down to remove nonrelevant settings.
{
"workbench.statusBar.visible": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
//"shellformat.useEditorConfig": true,
"editor.fontSize": 10,
"editor.tabCompletion": "on",
"editor.renderWhitespace": "all",
"editor.suggestSelection": "first",
"editor.codeLens": true,
// Generic
"cSpell.enabled": true,
"cSpell.language": "en",
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--disable=C0303",
"--indent-string=\" \""
],
"python.linting.pylintEnabled": true,
"python.autoComplete.addBrackets": true,
"python.terminal.activateEnvironment": true,
"[python]": {
"editor.defaultFormatter": "ms-python.vscode-pylance",
"editor.tabSize": 4,
"editor.autoClosingBrackets": "always",
"editor.insertSpaces": true,
},
"prettier.useEditorConfig": true,
"prettier.tabWidth": 4,
"python.linting.pylintCategorySeverity.convention": "Hint",
"python.linting.pylintCategorySeverity.refactor": "Warning",
"python.linting.maxNumberOfProblems": 200,
"python.linting.pycodestyleArgs": [
"--max-line-length=100"
],
"python.jediEnabled": false,
"vsintellicode.python.completionsEnabled": true,
"[json]": {
"editor.insertSpaces": true
},
// R
"[r]": {
"editor.autoClosingBrackets": "always",
"editor.defaultFormatter": "Ikuyadeu.r",
"editor.comments.insertSpace": true,
},
"r.interpreter": 0,
"r.linting.enable": true,
"r.lsp.debug": true,
"r.linting.maxLineLength": 105,
"r.editor.tabSize": 2,
"r.linting.noTabs": true,
"editor.detectIndentation": false,
"editor.comments.insertSpace": true,
"prettier.useTabs": false,
"editor.useTabStops": true,
"editor.stickyTabStops": false,
"update.enableWindowsBackgroundUpdates": false,
"breadcrumbs.enabled": true,
// REMOTE connection
"remote.SSH.showLoginTerminal": true,
"remote.SSH.lockfilesInTmp": true,
"window.openFoldersInNewWindow": "on",
"search.showLineNumbers": true,
"r.lsp.diagnostics": false,
"diffEditor.ignoreTrimWhitespace": false,
"workbench.iconTheme": "vscode-icons",
"material-icon-theme.showUpdateMessage": false,
"window.zoomLevel": 3,
"sync.removeExtensions": true,
"sync.syncExtensions": true,
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.analysis.extraPaths": [],
"python.terminal.activateEnvInCurrentTerminal": true,
"python.workspaceSymbols.enabled": true,
"python.analysis.completeFunctionParens": true,
"python.languageServer": "None",
"gitlens.currentLine.enabled": false,
"gitlens.hovers.currentLine.over": "line",
"gitlens.statusBar.enabled": false,
"jupyter.askForKernelRestart": false,
"[ignore]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"editor.autoIndent": "brackets",
"formattingToggle.affects": [
"editor.formatOnPaste",
"editor.formatOnSave",
"editor.formatOnType"
],
}

Is there a list of all VS Code settings.json fields?

In the example settings.json below, the html.fake setting is greyed out with the error Unknown Configuration Setting, meaning VSCode is aware of all possible config settings.
Is there a way to view this full list, or view an example settings.json with the default values for all accepted fields?
{
"html.autoClosingTags": "never",
"html.fake": "never"
}
I understand extensions may have their own config settings; I'm only interested in the base settings.
Please find the list of all default settings for VSCode(Link). I believe this is what you are looking for.
{
"files.autoSave": "afterDelay",
//"workbench.colorTheme": "Dracula Soft",
//"compile-hero.generate-minified-html": true,
//"compile-hero.generate-minified-css": true,
"php.validate.executablePath": "C:/php-7.4.28/php.exe",
"php.executablePath": "C:/php-7.4.28/php.exe",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
//"editor.renderIndentGuides": true,
"editor.fontWeight": "normal",
"editor.detectIndentation": false,
"editor.tabSize": 3,
"editor.suggestSelection": "first",
"editor.codeLensFontFamily": "Fira Code, Operator Mono",
"editor.codeLensFontSize": 16,
"breadcrumbs.enabled": false,
"editor.fontSize": 15,
"editor.fontFamily": "Fira Code, Operator Mono",
"editor.fontLigatures": "terminal.integrated.cursorWidth",
"editor.cursorWidth": 2,
"editor.lineHeight": 24,
// cursor
"editor.cursorSmoothCaretAnimation": true,
"editor.cursorBlinking": "expand",
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true,
"tag": true,
"class": true,
"id": true
},
// config related to code formatting
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
"[javascript]": {
"editor.formatOnSave": true
},
"[javascriptreact]": {
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.tslint": true,
"source.organizeImports": true
},
//terminal
//"terminal.integrated.cursorSmoothCaretAnimation": true,
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.fontSize": 16,
"terminal.integrated.lineHeight": 1.5,
//"terminal.integrated.fontWeight": "normal",
"terminal.integrated.fontFamily": "Fira Code, Operator Mono",
"terminal.integrated.cursorWidth": 2,
// "terminal.integrated.shell.windows": "C:/Users/user/AppData/Local/Microsoft/WindowsApps/wt.exe",
"terminal.integrated.automationShell.windows": null,
// terminal customization
"workbench.colorCustomizations": {
"terminal.ansiBlack": "#171c2a",
"terminal.ansiRed": "#E35535",
"terminal.ansiGreen": "#52AB62",
"terminal.ansiYellow": "#ffd866",
"terminal.ansiBlue": "#00B3BD",
"terminal.ansiMagenta": "#e991e3",
"terminal.ansiCyan": "#78e8c6",
"terminal.ansiWhite": "#FFFFFFcc",
"terminal.ansiBrightBlack": "#00B3BD",
"terminal.ansiBrightRed": "#E35535",
"terminal.ansiBrightGreen": "#52AB62",
"terminal.ansiBrightYellow": "#ffd866",
"terminal.ansiBrightBlue": "#00B3BD",
"terminal.ansiBrightMagenta": "#e991e3",
"terminal.ansiBrightCyan": "#78e8c6",
"terminal.ansiBrightWhite": "#ffffff",
"terminal.background": "#171c2a",
"terminalCursor.background": "#ffd866",
"terminalCursor.foreground": "#ffd866",
// Editor customaize
// "editorIndentGuide.activeBackground": "#430f7e",
// "editorIndentGuide.background": "#3a383a",
// "activityBar.background": "#740ee9f8",
// "editorBracketMatch.background": "#430f7e",
// "editorBracketMatch.border": "#ffffff",
//"editor.wordHighlightStrongBackground": "#740ee9f8",
"editor.wordHighlightBorder": "#740ee9f8",
//"editor.rangeHighlightBackground": "#740ee9f8",
// "editor.rangeHighlightBorder": "#740ee9f8",
"editor.selectionBackground": "#c7c7c76b",
// "editor.selectionHighlightBorder": "#ffffff",
// "tab.activeBackground": "#5332a0",
// "tab.border": "#430f7e"
},
// "prettier.disableLanguages": ["html", "css"],
"dictCompletion.addSpaceAfterCompletion": true,
"beautify.language": {
"js": {
"type": ["javascript", "json", "jsonc"],
"filename": [".jshintrc", ".jsbeautifyrc"]
},
"css": ["css", "scss"],
"html": ["htm", "html", "css", "javascript", "php", "blade"],
"php": ["javascript", "php", "blade"]
},
"phpformatter.logging": true,
"[json]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"workbench.colorTheme": "Learn with Sumit - Peace of the eye",
"workbench.iconTheme": "vscode-icons",
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"cSpell.userWords": [
"backorder"
],
"explorer.confirmDelete": false,
"window.zoomLevel": 1,
}
I hope you got the answering.

How to set indent and formatting behavior for each language in visual studio code?

Is there a way to make vscode format python files using 4 spaces while formatting files from other languages such JS, Typescript and HTML using 2 spaces only?
It`s pretty annoying to have to indent manually every time.
All of this trying is setting up a mess on my settings and still, I can`t make it work as I want.
This is what my settings.json looks like for the moment
{
"python.jediEnabled": false,
"miramac.node.terminalMode": false,
"python.pythonPath": "/usr/local/bin/python3",
"workbench.colorTheme": "Dracula",
"workbench.startupEditor": "newUntitledFile",
"workbench.editor.labelFormat": "short",
"terminal.integrated.fontSize": 12,
"editor.fontFamily": "Fira Code",
"editor.lineHeight": 19,
"editor.fontLigatures":true,
"editor.suggestSelection": "first",
"editor.renderLineHighlight": "gutter",
"editor.detectIndentation": true,
"editor.insertSpaces": false,
"editor.tabSize": 2,
"editor.autoIndent": "full",
"eslint.alwaysShowStatus": true,
"eslint.debug": true,
"eslint.format.enable": true,
"eslint.options": {
},
"python.languageServer": "Microsoft",
"liveServer.settings.donotVerifyTags": true,
"[html]": {
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
},
"liveServer.settings.donotShowInfoMsg": true,
"prettier.tabWidth": 2,
"[javascript]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
}
},
"[javascriptreact]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
}
},
"[typescript]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[typescriptreact]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[python]": {
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
// "source.fixAll": true,
},
},
"extensions.ignoreRecommendations": true,
"explorer.compactFolders": false,
//perguntar se vc confirma delete e drag and drops
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
//mostra o caminho completo do arquivo
"breadcrumbs.enabled": true,
"javascript.updateImportsOnFileMove.enabled": "never",
"typescript.updateImportsOnFileMove.enabled": "never",
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame"
],
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
//set zsh theme to my terminal
//"terminal.integrated.shell.osx": "/bin/bash",
"terminal.integrated.shell.osx": "/bin/bash",
//"terminal.integrated.cwd": "",
"editor.renderControlCharacters": false,
"window.zoomLevel": -1,
"git.path": "/usr/local/git/bin/git",
"gitlens.views.repositories.files.layout": "list",
"gitlens.views.compare.files.layout": "tree",
"emmet.syntaxProfiles": {"javascript": "jsx"},
"emmet.includeLanguages": {"javascript": "javascriptreact"},
"typescript.tsserver.log": "verbose",
"javascript.suggest.autoImports": true,
"git.enableCommitSigning": true,
"git.enableSmartCommit": true,
"git.rebaseWhenSync": true,
"git.showPushSuccessNotification": true,
"workbench.sideBar.location": "left",
"workbench.activityBar.visible": true,
"terminal.integrated.automationShell.osx": "",
// "editor.defaultFormatter": "vscode.python",
// "editor.tokenColorCustomizationsExperimental": {},
"workbench.preferredDarkColorTheme": "Dracula",
"workbench.preferredHighContrastColorTheme": "Visual Studio Dark",
"material-icon-theme.activeIconPack": "nest",
"workbench.iconTheme": "material-icon-theme",
"material-icon-theme.folders.associations": {
"infra": "app",
"entities": "class",
"schemas": "class",
"typeorm": "database",
"repositories": "mappings",
"http": "container",
"migrations": "tools",
"modules": "components",
"implementations": "core",
"dtos": "typescript",
"fakes": "mock",
"coverage_reports": "tools",
},
"material-icon-theme.files.associations": {
"ormconfig.json": "database",
"routes.tsx": "routing",
"routes.ts": "routing",
"*.html": "html",
},
"sqlite.databaseExtensions": [
"db",
"db3",
"sdb",
"s3db",
"sqlite",
"sqlite3",
"ts"
],
}
Would there be anyone who can help in this issue?
I believe option + control + "B" should work
It is also a right click on the document and you should see a "format document" option.
It works for me

VS Code is formatting JS files with operators on new line

For the life of me I cannot figure this out. I have a complex VSCode setup and I believe the prettier extension is causing some behavior I do not want, and I hope someone knows how to disable or re-configure it:
JS files:
takes:
child.gender = $(pref).find('#ml').prop('checked')? 'male' : 'female';
And renders:
child.gender = $(pref)
.find('#ml')
.prop('checked')
? 'male'
: 'female';
I really need the formatter and would like to try to fix rather than disable.
Thanks for your help.
existing options:
"workbench.iconTheme": "material-icon-theme",
"php.suggest.basic": false,
"editor.minimap.enabled": false,
"editor.fontLigatures": true,
"editor.fontFamily": "'Fira Code', 'Arial', monospace",
"php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.2.4\\php.exe",
"files.associations": {
"*.php": "php",
"*.phtml": "php"
},
"php.validate.run": "onType",
"editor.cursorSmoothCaretAnimation": true,
"editor.smoothScrolling": true,
"files.trimFinalNewlines": true,
"emmet.includeLanguages": {
"blade.php": "html"
},
"vetur.format.options.tabSize": 4,
"vetur.format.options.useTabs": false,
"blade.format.enable": true,
"vetur.format.defaultFormatter.html": "prettyhtml",
"vetur.format.defaultFormatter.css": "prettier",
"vetur.format.defaultFormatter.postcss": "prettier",
"vetur.format.defaultFormatter.scss": "prettier",
"vetur.format.defaultFormatter.less": "prettier",
"vetur.format.defaultFormatter.stylus": "stylus-supremacy",
"vetur.format.defaultFormatter.js": "prettier",
"vetur.format.defaultFormatter.ts": "prettier",
"eslint.enable": false,
"window.zoomLevel": 0,
"files.trimTrailingWhitespace": true,
"prettier.singleQuote": true,
"prettier.trailingComma": "es5",
"prettier.eslintIntegration": true,
"prettier.disableLanguages": [],
"eslint.autoFixOnSave": true,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.detectIndentation": true,
"editor.tabSize": 4,
"editor.formatOnPaste": false,
"editor.formatOnType": true,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "none",
"files.exclude": {
".babelrc": true,
".editorconfig": true,
".eslintignore": true,
".eslintrc.js": false,
".gitignore": true,
".jshintrc": true,
".postcssrc.js": true,
"**/node_modules": true,
"build": true
},
"eslint.validate": [
{
"autoFix": true,
"language": "javascript"
},
{
"autoFix": true,
"language": "vue"
}
],
"attrsSorter.order": [
"is",
"v-for",
"v-if",
"v-else-if",
"v-else",
"v-show",
"v-cloak",
"v-once",
"v-pre",
"id",
"ref",
"key",
"slot",
"v-model",
"v-model.+",
"v-bind",
"v-bind.+",
":.+",
"v-text",
"v-text.+",
"v-html",
"v-html.+",
"class",
"v-on.+",
"#.+",
"name",
"data-.+",
"ng-.+",
"src",
"for",
"type",
"href",
"values",
"title",
"alt",
"role",
"aria-.+",
"$unknown$"
],
"gitlens.currentLine.enabled": false,
"gitlens.hovers.currentLine.over": "line",
"gitlens.codeLens.enabled": false,
"phpformatter.composer": true,
"phpformatter.pharPath": "php-cs-fixer",
"phpformatter.logging": true,
"laravel_goto_view.quickJump": true,
"laravel_goto_view.folderTip": true,
"git.enableSmartCommit": true,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": true,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true,
"bracketPairColorizer.highlightActiveScope": true