I would like to specify settings in VS Code that only apply when working with a (Jupyter) notebook.
I know language-specific settings are possible with this syntax, e.g. for Python:
"[python]": {
"editor.some.setting": "something"
}
However, there seems to be no option to select python-notebook or something similar as a language. Is there any workaround for this?
(Specifically, I would like to disable the final newline for autopep8 formatting when inside a Jupiter notebook by setting "python.formatting.autopep8Args": ["--ignore", "W292"])
Related
I cannot locate the settings or other configurations that define the colors and other formatting shown in VS Code's Terminal output. I'd like to mimic or use these settings elsewhere, such as in word processing software, HTML/CSS, or simply a Language Mode when copying & pasting the output into a new VS Code file.
Where is this formatting defined? Also, how can I keep this formatting intact when using the text elsewhere?
I'm editing GML files (GameMaker Studio) in VSCode. There's a wonderful plugin, GML Support which adds autocomplete for inbuilt GML functions and instances variables along with a bunch of other cool things.
However, VSCode doesn't seem to recognise local variables in GML (see screen grab below. Dot notation works fine)
I had a look at the VSCode's Programmatic Language Extension for variable name auto-completion but still don't get how I could register the variable declaration (i.e. var fooBar = 23;) with VSCode's Language Server.
Ideally, I'd like the Language Server to respect variable scope for GML files:
global variables - any var declarations for files under script folder
any local variable declarations - all var declarations in the surrounding {...}
What would be the easiest way to add variable name completion as described above?
Thanks in advance!
Edit: looked at vscode-python to see how registerCompletionItemProvider (based on VSCode Language Extension doco) could be used. Unfortunately, still not clear to me as vscode-python seem to rely on Jedi to provide symbols?
So any points appreciated!
If you want to enable simple auto-completion, you can add the following to your settings.json (Command Palette ➜ Open Settings (JSON)):
"[gml-gms81]": { "editor.quickSuggestions": true },
"[gml-gms1]": { "editor.quickSuggestions": true },
"[gml-gms2]": { "editor.quickSuggestions": true },
which works for a workaround:
For a proper solution, well, you'll need to use the registerCompletionItemProvider and index the file on demand or as you go.
The official example demonstrates the use.
For intricacies of processing GML syntax, you can peck at the code in the Ace-based external editor that I made. Processing variable definitions specifically requires you to skip over strings, comments, and loop over values (var name[=value][, name2[=value2]]) with relative degree of confidence (which can be accomplished through a balanced parser).
I want to change tabs to whitespaces when I save the file.
I thought there would an option in the settings or at least an extension, but I was not able to see it.
I have seen many other posts for removing trim.trailingWhitespace, but that is not what I am looking for.
I am also using the conversion from tabs to whitespaces when pressing the Tab key. But that is, again, not my issue.
What I am looking for is to save the file and automatically change all the tabs to whitespaces, like Qt Creator does.
It is going to depend on the language. You need to install/setup a language-specific formatter and then enable the "editor.formatOnSave" setting, which will literally apply the formatter rules when saving files.
This answer is for Python and JavaScript because that's what I normally use.
For JavaScript, I use the Prettier extension.
(It has plugins for other languages but I've mainly used it for JS.)
Then add these to your settings.json:
// Set the default setting
"editor.formatOnSave": false,
// Then toggle depending on the language
"[javascript]": {
"editor.formatOnSave": true
},
By default, Prettier already provides some default formatting rules. But you can specify your own configuration file to specify your own (or a project-specific) set of formatting rules.
.
├── ...
├── .prettierrc.js
├── test.js
...
└── <<other files>>
In .prettierrc.js:
// prettier.config.js or .prettierrc.js
module.exports = {
useTabs: false,
tabWidth: 4
};
That Prettier config specifies not to use tabs and use an indentation level of 4 spaces. Now, with that setup, when you save a file, it will automatically change tabs to whitespaces (which is what I understand is what you want). There are also other formatting options.
You'll know the extension is working because it shows "Prettier" in the status bar:
For Python, VS Code currently supports 3 formatting providers):
"autopep8"
"yapf"
"black".
I use "autopep8".
Install autopep8 on your environment. Then in VS Code, make sure to select the environment that has autopep8. Then add this to your settings.json:
// Set the default setting
"editor.formatOnSave": false,
"[python]": {
"editor.formatOnSave": true
},
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
// "--ignore=W191, E101, E111" // Uncomment to disable fixing indentation
],
Here, autopep8 formats code to follow the PEP8 style guide, which already recommends spaces over tabs. So all that needs to be done is enable it.
You might also be interested in VS Code settings related to spaces (so that tabs will not be put into the file in the first place):
"editor.detectIndentation": false,
"editor.insertSpaces": true,
"editor.tabSize": 4,
Whenever I face an indentation problem, I go online and google "beautify python code" and the 2nd or 3rd link of tutorials-point helps me out( link ).
Just put in your code and it will (in most cases) completely fix it for you or guide you theough the errors in a better way than an interpreter.
I am using windows and VS Code, I have few files that I do not need to wrap them wherever I press Alt+Shift+F, is there a way to disable auto format wrapping for specific files?
Explained here Language-specific editor settings but specifically:
CTRL+SHIFT+P and type "Preferences: Configure Language Specific Settings"
Select the language or add section in the file (start typing [ to see list of suggestions) or edit if already there.
If wrapping, depending on columns available in your editor you might want to update editor.wordWrapColumn. Lines will wrap at the minimum of viewport and editor.wordWrapColumn
Example:
...
"editor.wordWrapColumn": 200,
"[typescript]": {
"editor.tabSize": 2,
"editor.wordWrap": "off",
},
"[plaintext]": {
"editor.wordWrap": "bounded",
},
...
Looks like VSCode allows for this. You can tweak it as you prefer for each file type.
However note that there have been reports of it not working for markdown files.
I guess it is something still being tweaked.
Looks like this person made an extension that might be useful for you.
https://marketplace.visualstudio.com/items?itemName=Ho-Wan.setting-toggle
Looks like you can setup a few quick easy setting toggles. would at least make it quicker as you're bouncing from file to file.
Visual Studio Code Version 1.10 adds the ability to specify languages settings on a per language basis (*1). You put something like this in your settings.json file:
"[javascript]": {
"editor.fontSize": 100,
}
I'd like to do something more specific. I'd like to apply different rules to files that match *.min.js.
How would I do that?
I've actually got something that works, but it's a bit hacky, so I thought I'd ask.
*1) In case you want to know which ones: Use autocomplete after typing in "[]":, or see languageIds array in this file.
I'm aware beautify skips formatting min files by default. But just using "editor.formatOnSave": true, this doesn't seem to happen. Also, other non-formatting stuff like wordwrap is nice.
Here's my current solution:
"files.associations": {
"*.min.js": "javascriptreact"
},
// Hijack javascriptreact to create custom settings for min.js files
"[javascriptreact]": {
"editor.formatOnSave": false,
"editor.wordWrap": "on"
}
I'm using the fact that vscode happens to have a second type of javascript, one that isn't used my my project. Not ideal, but it seems to work.