Автоматическая сортировка import в visual studio code
JS/TS Import/Export Sorter
Automatically format imports and exports for JavaScript and TypeScript in VSCode.
- Support formatting Import Assertions.
- Add root config to support monorepo projects.
- Add preserve option for insertFinalNewline config.
- Add ignoreESLintRules config to ignore specific ESLint rules.
- Add always option for trailingComma config.
- Support new ESLint rules: and @typescript-eslint/semi and @typescript-eslint/comma-dangle and @typescript-eslint/object-curly-spacing
- Update default GroupRules to group node: imports separately.
- Fix Prettier option "trailingComma": "es5" .
Table of contents
Auto format on save when autoFormat is set to onSave (this is the default).
Auto format via Code Actions on Save (VSCode 1.44+)
Press shortcut keys, default to Alt+Shift+S .
Use Sort Imports/Exports command in the Command Palette ( Ctrl+Shift+P ).
Right click on editor content and select Sort Imports/Exports .
The extension reads configurations from the following sources (in precedence from high to low):
-
if installed.
- "importSorter" section in package.json
- import-sorter.json (File name is configurable) if installed
- .editorconfig
- VS Code "editor" and "files" settings
- VS Code "tsImportSorter" settings
The following settings (and default values) are available in VSCode User Settings for this extension:
Most of the above settings, plus more in Configuration are also available in import-sorter.json or package.json under "importSorter section.
If installed, ESLint and plugins rules will be detected and consulted, so that the result code will comply to the lint rules.
For how it works, please check the ESLint Compatibility wiki.
When reading config from import-sorter.json or package.json , Format-Imports will automatically look for them in the directory of the file to be formatted, and in successive parent directories all the way up to the root directory of the filesystem (unless "root": true is specified).
Multiple import-sorter.json or package.json files can be useful when you want different configurations for different sub projects of your monorepo, while common settings are kept in the root import-sorter.json or package.json . When there is a conflict, the sub project (more localized) config will take precedence.
This is an open source project so your contribution will be well appreciated.
Sort ES6 imports for JavaScript and TypeScript automatically. Ported from the atom-import-sort package by Renke Grunwald.
Features
Automatically sorts imports on save. You can disable this behavior in the settings and sort imports manually:
- Launch the Command Palette ( Ctrl/Cmd + Shift + P );
- Enter Sort imports
You can also save the document without saving imports. This could become handy when you have auto saving enabled, but don't want to sort the imports in a particular file:
- Launch the Command Palette ( Ctrl/Cmd + Shift + P );
- Enter Save file without sorting imports
Extension Settings
This extension has the following settings:
- sort-imports.default-sort-style : sorting style if package.json doesn't have import-sort key (default: eslint ).
- sort-imports.on-save : enable/disable auto sorting on save (default: true ).
- sort-imports.ignore-type-defs : will not sort .d.ts files by default since import-sort doesn't handle them well (default: true ).
- sort-imports.languages : selectively choose the languages which should be sorted (default: ['javascript', 'typescript'] ).
- sort-imports.cache-package-json-config-checks : The sort config is only checked when config files change as a performance optimization, disable if necessary (default: true ).
Obsolete settings
Use a different style or parser
Styles (and parsers) can be configured on a per-project basis including support for different types of files (currently JavaScript and TypeScript).
Just add the following to your package.json and adapt it to your liking:
The keys are a list of file extensions that map to the parser and style that should be used for files that have any of the listed file extensions.
By default, sort-imports comes with these styles:
import-sort-style-module : A style that groups and sorts by module.
import-sort-style-module-compact : Similar to modules but with fewer groups.
import-sort-style-module-scoped : A style for import-sort that is focused on modules but with scope support.
PRs with more styles are welcome.
Troubleshooting
parser.parseImports is not a function
Visual Studio Code is a powerful editing tool for Python source code. The editor includes various features to help you be productive when writing code. For more information about editing in Visual Studio Code, see Basic Editing and Code Navigation.
In this overview, we will describe the specific editing features provided by the Python extension, including steps on how to customize these features via user and workspace settings.
Autocomplete and IntelliSense
IntelliSense is a general term for code editing features that relate to code completion. Take a moment to look at the example below. When print is typed, notice how IntelliSense populates auto-completion options. The user is also given a list of options when they begin to type the variable named, greeting.
Autocomplete and IntelliSense are provided for all files within the current working folder. They're also available for Python packages that are installed in standard locations.
Customize IntelliSense behavior
To customize the behavior of the analysis engine, see the Python extension code analysis settings and autocomplete settings.
You can also customize the general behavior of autocomplete and IntelliSense, even to disable these VS Code features entirely. See Customizing IntelliSense.
Tip: Check out the IntelliCode extension for VS Code (preview). IntelliCode provides a set of AI-assisted capabilities for IntelliSense in Python, such as inferring the most relevant auto-completions based on the current code context. For more information, see the IntelliCode for VS Code FAQ.
Enable IntelliSense for custom package locations
To enable IntelliSense for packages that are installed in other, non-standard locations, add those locations to the python.autoComplete.extraPaths collection in the settings file (the default collection is empty). For example, you might have installed Google App Engine installed in custom locations, specified in app.yaml if you use Flask. In this case, you'd specify those locations as follows:
Windows:
macOS/Linux:
For more on IntelliSense generally, see IntelliSense.
Troubleshooting IntelliSense
If autocomplete and IntelliSense aren't working for a custom module, check the following causes:
Cause | Solution |
---|---|
The path to the python interpreter is incorrect | Make sure you selected a valid interpreter path by running the Python: Select Interpreter command (see Environments). |
The custom module is located in a non-standard location (not installed using pip). | Add the location to the python.autoComplete.extraPaths setting and restart VS Code. |
Navigation
While editing, you can right-click different identifiers to take advantage of several convenient commands
Go to Definition ( F12 ) jumps from your code into the code that defines an object. This command is helpful when you're working with libraries.
Peek Definition ( ⌥F12 (Windows Alt+F12 , Linux Ctrl+Shift+F10 ) ), is similar, but displays the definition directly in the editor (making space in the editor window to avoid obscuring any code). Press Escape to close the Peek window or use the x in the upper right corner.
Go to Declaration jumps to the point at which the variable or other object is declared in your code.
Peek Declaration is similar, but displays the declaration directly in the editor. Again, use Escape or the x in the upper right corner to close the Peek window.
Quick Fixes
The add imports Quick Fix allows you to quickly complete import statements. First, begin by typing a package name within the editor. You will notice a Code Action is available to automatically complete the line of source code (as long as you have the module installed within the environment). Hover over the text (marked with a squiggle) and then select the Code Action light bulb when it appears. You can then select from a list of potential imports. Note: The functionality in the below examples is provided by the Pylance language server.
The add imports Code Action also recognizes some of the popular abbreviations for the following common Python packages: numpy as np, tensorflow as tf, pandas as pd, matplotlib.pyplot as plt, matplotlib , as mpl, math as m, scipi.io as spio, and scipy as sp, panel as pn, and holoviews as hv.
The import suggestions list is ordered with import statements for packages (or modules) at the top. It will also include statements for more modules and/or members (classes, objects, etc.) from specified packages.
Run Selection/Line in Terminal (REPL)
The Python: Run Selection/Line in Python Terminal command ( Shift+Enter ) is a simple way to take whatever code is selected, or the code on the current line if there is no selection, and run it in the Python Terminal. An identical Run Selection/Line in Python Terminal command is also available on the context menu for a selection in the editor.
VS Code automatically removes indents based on the first non-empty line of the selection, shifting all other lines left when needed.
Source code that runs in the terminal/REPL is cumulative until the current instance of the terminal is closed.
The command opens the Python Terminal if necessary; you can also open the interactive REPL environment directly using the Python: Start REPL command. (Initial startup might take a few moments especially if the first statement you run is an import .)
On first use of the Python: Run Selection/Line in Python Terminal command, VS Code may send the text to the REPL before that environment is ready, in which case the selection or line isn't run. If you come across this behavior, try the command again when the REPL has finished loading.
Formatting
Formatting makes code easier to read by human beings. It applies specific rules and conventions for line spacing, indents, spacing around operators, and so on. You can view an example on the autopep8 page. Keep in mind, formatting doesn't affect the functionality of the code itself.
Linting helps to prevent errors by analyzing code for common syntactical, stylistic, and functional errors and unconventional programming practices. Although there is a little overlap between formatting and linting, the two capabilities are complementary.
The Python extension supports source code formatting using either autopep8 (the default), black, or yapf.
General formatting settings
Setting (python.formatting.) | Default value | Description |
---|---|---|
provider | "autopep8" | Specifies the formatter to use, either "autopep8", "yapf", or "black". |
Formatter-specific settings
The following settings apply to the individual formatters. The Python extension looks for the formatter in the selected interpreter. To use a formatter in another location, specify that location in the appropriate custom path setting. The pip install commands may require elevation.
Formatter | Install steps | Arguments setting (python.formatting.) | Custom path setting (python.formatting.) |
---|---|---|---|
autopep8 | pip install pep8 pip install --upgrade autopep8 | autopep8Args | autopep8Path |
black (see note) | pip install black | blackArgs | blackPath |
yapf | pip install yapf | yapfArgs | yapfPath |
Note: By default, the Black formatter can't be installed when a Python 2 environment is active. Attempting to do so may display the message "Formatter black is not installed. Install?". If you try to install Black in response, another message appears saying "Could not find a version that satisfies the requirement black' No matching distribution found for black."
To work around this issue and use the Black formatter with Python 2, first install Black in a Python 3 environment. Then set the python.formatting.blackPath setting to that install location.
When using custom arguments, each top-level element of an argument string that's separated by space on the command line must be a separate item in the args list. For example:
In the second example, the top-level element is a single value contained in braces, so the spaces within that value don't delineate a separate element.
Troubleshooting formatting
If formatting fails, check the following possible causes:
Cause | Solution |
---|---|
The path to the python interpreter is incorrect. | Make sure you selected a valid interpreter path by running the Python: Select Interpreter command. |
The formatter is not installed in the current environment. | Open a command prompt, navigate to the location where your selected interpreter is, and run pip install for the formatter. |
The path to the formatter is incorrect. | Check the value of the appropriate python.formatting.Path setting. |
Custom arguments for the formatter are incorrect. | Check that the appropriate python.formatting.Path setting does not contain arguments, and that python.formatting.Args contains a list of individual top-level argument elements such as "python.formatting.yapfArgs": ["--style", ""] . |
Pop up with warning message Black does not support the "Format Select" command. | black does not support formatting sections of code, it can be prevented with the following settings "[python]": . |
Refactoring
The Python extension adds the following refactoring functionalities: Extract Variable, Extract Method, Rename Module, and Sort Imports.
Extract Variable
Extracts all similar occurrences of the selected text within the current scope, and replaces it with a new variable.
You can invoke this command by selecting the line of code you wish to extract as a variable. Then select the light-bulb that is displayed next to it.
Extract Method
Extracts all similar occurrences of the selected expression or block within the current scope, and replaces it with a method call.
You can invoke this command by selecting the lines of code you wish to extract as a method. Then select the light-bulb that is displayed next to it.
Rename Module
After a Python file/module is renamed, Pylance can find all instances that may need to be updated and provide you with a preview of all the changes.
To customize which references need to be updated, you can toggle the checkboxes at the line or from the file level in Refactor Preview. Once you've made your selections, you can select Apply Refactoring or Discard Refactoring.
Sort Imports
Sort Imports uses the isort package to consolidate specific imports from the same module into a single import statement and to organize import statements in alphabetical order.
- Right-click in editor and select Sort Imports (no selection is required)
- Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ), then Python Refactor: Sort Imports
- Assign a keyboard shortcut to the python.sortImports command
Custom arguments to isort are specified in the python.sortImports.args setting, where each top-level element, as separated by spaces on the command line, is a separate item in the array:
To use a custom isort script, use the python.sortImports.path setting to specify the path.
Further configurations can be stored in an .isort.cfg file as documented on isort configuration.
Note: For those migrating from isort4 to isort5, some CLI flags and config options have changed, refer to the project's isort5 upgrade guide.
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust components.
Installing the TypeScript compiler
Visual Studio Code includes TypeScript language support but does not include the TypeScript compiler, tsc . You will need to install the TypeScript compiler either globally or in your workspace to transpile TypeScript source code to JavaScript ( tsc HelloWorld.ts ).
The easiest way to install TypeScript is through npm, the Node.js Package Manager. If you have npm installed, you can install TypeScript globally ( -g ) on your computer by:
You can test your install by checking the version.
Another option is to install the TypeScript compiler locally in your project ( npm install --save-dev typescript ) and has the benefit of avoiding possible interactions with other TypeScript projects you may have.
Syntax highlighting and semantic highlighting
In addition to syntax highlighting, TypeScript and JavaScript also provide semantic highlighting.
Syntax highlighting colors the text based on lexical rules. Semantic highlighting enriches the syntax coloring based on resolved symbol information from the language service.
Whether semantic highlighting is visible depends on the current color theme. Each theme can configure whether to display semantic highlighting and how it styles the semantic tokens.
If semantic highlighting is enabled and the color theme has a corresponding styling rule defined, different colors and styles can be seen.
Semantic highlighting can change colors based on:
- The resolved type of a symbol: namespace, variable, property, variable, class, interface, typeParameter.
- Whether the variable/property is read-only (const) or modifiable.
- Whether the variable/property type is callable (a function type) or not.
IntelliSense
IntelliSense shows you intelligent code completion, hover info, and signature information so that you can write code more quickly and correctly.
Sorry, your browser doesn't support HTML 5 video.
VS Code provides IntelliSense for individual TypeScript files as well as TypeScript tsconfig.json projects.
Snippets
VS Code includes basic TypeScript snippets that are suggested as you type;
Sorry, your browser doesn't support HTML 5 video.
You can install extensions to get additional snippets or define your own snippets for TypeScript. See User Defined Snippets for more information.
Tip: You can disable snippets by setting editor.snippetSuggestions to "none" in your settings file. If you'd like to see snippets, you can specify the order relative to suggestions; at the top ( "top" ), at the bottom ( "bottom" ), or inlined ordered alphabetically ( "inline" ). The default is "inline" .
JSDoc support
VS Code's TypeScript IntelliSense understands many standard JSDoc annotations, and uses them to show typing information and documentation in suggestions, hover info, and signature help.
Keep in mind that when using JSDoc for TypeScript code, you should not include type annotations. The TypeScript compiler only uses TypeScript type annotations and ignores those from JSDoc.
Sorry, your browser doesn't support HTML 5 video.
To disable JSDoc comment suggestions in TypeScript, set "typescript.suggest.completeJSDocs": false .
Hover information
Hover over a TypeScript symbol to quickly see its type information and relevant documentation:
You can also show the hover info at the current cursor position with the ⌘K ⌘I (Windows, Linux Ctrl+K Ctrl+I ) keyboard shortcut.
Signature help
As you write a TypeScript function call, VS Code shows information about the function signature and highlights the parameter that you are currently completing:
Signature help is shown automatically when you type a ( or , within a function call. Use ⇧⌘Space (Windows, Linux Ctrl+Shift+Space ) to manually trigger signature help.
Auto imports
Automatic imports speed up coding by helping you find available symbols and automatically adding imports for them.
Just start typing to see suggestions for all available TypeScript symbols in your current project.
If you choose one of the suggestions from another file or module, VS Code will automatically add an import for it. In this example, VS Code adds an import for Hercules to the top of the file:
You can disable auto imports by setting "typescript.suggest.autoImports": false .
Formatting
VS Code includes a TypeScript formatter that provides basic code formatting with reasonable defaults.
Use the typescript.format.* settings to configure the built-in formatter, such as making braces appear on their own line. Or, if the built-in formatter is getting in the way, set "typescript.format.enable" to false to disable it.
For more specialized code formatting styles, try installing one of the formatting extensions from the VS Code marketplace.
JSX and auto closing tags
VS Code's TypeScript features also work with JSX. To use JSX in your TypeScript, use the *.tsx file extension instead of the normal *.ts :
VS Code also includes JSX-specific features such as autoclosing of JSX tags in TypeScript:
Sorry, your browser doesn't support HTML 5 video.
Set "typescript.autoClosingTags" to false to disable JSX tag closing.
Code navigation
Code navigation lets you quickly navigate TypeScript projects.
- Go to Definition F12 - Go to the source code of a symbol definition.
- Peek Definition ⌥F12 (Windows Alt+F12 , Linux Ctrl+Shift+F10 ) - Bring up a Peek window that shows the definition of a symbol.
- Go to References ⇧F12 (Windows, Linux Shift+F12 ) - Show all references to a symbol.
- Go to Type Definition - Go to the type that defines a symbol. For an instance of a class, this will reveal the class itself instead of where the instance is defined.
- Go to Implementation ⌘F12 (Windows, Linux Ctrl+F12 ) - Go to the implementations of an interface or abstract method.
You can navigate via symbol search using the Go to Symbol commands from the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ).
- Go to Symbol in File ⇧⌘O (Windows, Linux Ctrl+Shift+O )
- Go to Symbol in Workspace ⌘T (Windows, Linux Ctrl+T )
Rename
Press F2 to rename the symbol under the cursor across your TypeScript project:
Refactoring
VS Code includes some handy refactorings for TypeScript such as Extract function and Extract constant. Just select the source code you'd like to extract and then click on the lightbulb in the gutter or press ( ⌘. (Windows, Linux Ctrl+. ) ) to see available refactorings.
See Refactorings for more information about refactorings and how you can configure keyboard shortcuts for individual refactorings.
Available TypeScript refactorings include:
Extract to method or function - Extract the selected statements or expressions to either a new method or a new function in the file.
After selecting the Extract to method or Extract to function refactoring, enter the name of the extracted method/function.
Extract to constant - Extract the selected expression to a new constant in the file.
Extract type to interface or type alias - Extract the selected complex type to either an interface or a type alias.
Move to new file - Move one or more classes, functions, constants, or interfaces in the top-level scope of the file to a new file. The new file's name is inferred from the selected symbol's name.
Convert between named imports and namespace imports - Convert between named imports ( import < Name >from './foo' ) and namespace imports ( import * as foo from './foo' ).
Convert between default export and named export - Convert from using a export default and having a named export ( export const Foo = . ).
Generate get and set accessors - Encapsulate a selected class property by generating a getter and setter for it.
Convert parameters to destructured object - Rewrite a function that takes a long list of arguments to take a single arguments object.
Quick Fixes
Quick Fixes are suggested edits that address simple coding errors. Example Quick Fixes include:
- Adding a missing this to a member access.
- Fixing a misspelled property name.
- Removing unreachable code or unused imports
- Declaring
When you move your cursor on to a TypeScript error, VS Code shows a lightbulb that indicates that Quick Fixes are available. Click the lightbulb or press ⌘. (Windows, Linux Ctrl+. ) to show a list of available Quick Fixes and refactorings.
Unused variables and unreachable code
Unused TypeScript code, such as the else block of an if statement that is always true or an unreferenced import, is faded out in the editor:
You can quickly remove this unused code by placing the cursor on it and triggering the Quick Fix command ( ⌘. (Windows, Linux Ctrl+. ) ) or clicking on the lightbulb.
To disable fading out of unused code, set "editor.showUnused" to false . You can also disable fading of unused code only in TypeScript by setting:
Organize Imports
The Organize Imports source code action sorts the imports in a TypeScript file and removes unused imports:
Sorry, your browser doesn't support HTML 5 video.
You can run Organize Imports from the Source Action context menu or with the ⇧⌥O (Windows, Linux Shift+Alt+O ) keyboard shortcut.
Organize imports can also be done automatically when you save a TypeScript file by setting:
Code Actions on Save
The editor.codeActionsOnSave setting lets you configure a set of Code Actions that are run when a file is saved. For example, you can enable organize imports on save by setting:
You can also set editor.codeActionsOnSave to an array of Code Actions to execute in order.
Here are some source actions:
- "organizeImports" - Enables organize imports on save.
- "fixAll" - Auto Fix on Save computes all possible fixes in one round (for all providers including ESLint).
- "fixAll.eslint" - Auto Fix only for ESLint.
- "addMissingImports" - Adds all missing imports on save.
See TypeScript for more information.
Code suggestions
VS Code automatically suggests some common code simplifications such as converting a chain of .then calls on a promise to use async and await
Sorry, your browser doesn't support HTML 5 video.
Set "typescript.suggestionActions.enabled" to false to disable suggestions.
Inlay hints
Inlay hints add additional inline information to source code to help you understand what the code does.
Parameter name inlay hints show the names of parameters in function calls:
This can help you understand the meaning of each argument at a glance, which is especially helpful for functions that take Boolean flags or have parameters that are easy to mix up.
To enable parameter name hints, set typescript.inlayHints.parameterNames.enabled . There are three possible values:
- none — Disable parameter inlay hints.
- literals — Only show inlay hints for literals (string, number, Boolean).
- all — Show inlay hints for all arguments.
Variable type inlay hints show the types of variables that don't have explicit type annotations.
Property type inlay hints show the type of class properties that don't have an explicit type annotation.
Parameter type hints show the types of implicitly typed parameters.
Return type inlay hints show the return types of functions that don't have an explicit type annotation.
References CodeLens
The TypeScript references CodeLens displays an inline count of reference for classes, interfaces, methods, properties, and exported objects:
You can enable this by setting "typescript.referencesCodeLens.enabled": true in the User Settings file.
Click on the reference count to quickly browse a list of references:
Implementations CodeLens
The TypeScript implementations CodeLens displays the number of implementors of an interface:
You can enable this by setting "typescript.implementationsCodeLens.enabled": true .
As with the references CodeLens, you can click on the implementation count to quickly browse a list of all implementations.
Update imports on file move
When you move or rename a file that is imported by other files in your TypeScript project, VS Code can automatically update all import paths that reference the moved file.
- "prompt" - The default. Asks if paths should be updated for each file move.
- "always" - Always automatically update paths.
- "never" - Do not update paths automatically and do not prompt.
Debugging
VS Code comes with great debugging support for TypeScript, including support for sourcemaps. Set breakpoints, inspect objects, navigate the call stack, and execute code in the Debug Console. See the Debugging topic to learn more.
Debug client side
You can debug your client-side code using a browser debugger such as the built-in Edge and Chrome debugger, or the Debugger for Firefox.
Debug server side
Debug Node.js in VS Code using the built-in debugger. Setup is easy and there is a Node.js debugging tutorial to help you.
Linters
Linters provides warnings for suspicious looking code. While VS Code does not include a built-in TypeScript linter, TypeScript linter extensions available in the marketplace.
ESLint is a popular linter, which also supports TypeScript. The ESLint extension integrates ESLint into VS Code so you can see linting errors right in the editor and even quickly many of fix them with Quick Fixes. The ESLint plugin guide details how to configure ESLint for your TypeScript projects.
TypeScript extensions
VS Code provides many features for TypeScript out of the box. In addition to what comes built-in, you can install an extension for greater functionality.
Tip: Click on an extension tile above to read the description and reviews to decide which extension is best for you. See more in the Marketplace.
Next steps
To learn more, see:
-
- Create a simple Hello World TypeScript in VS Code. - Compile TypeScript to a JavaScript target version. - Learn about debugging TypeScript both server and client-side with VS Code.
Common questions
Can I use the version of TypeScript that ships with VS 2015?
No, the TypeScript language service that ships with Visual Studio 2015 and 2017 isn't compatible with VS Code. You will need to install a separate version of TypeScript from npm.
How can I use the latest TypeScript beta with VS Code?
The simplest way to try out the latest TypeScript features in VS Code is to install the JavaScript and TypeScript Nightly extension.
VSCode does have support to sort imports inside a .py file using isort. The recommended way to turn this on is via the following settings:
Sadly, this seems to ignore anything configured in python.sortImports.args and produces different and buggy results (e.g. duplicate imports) on subsequential runs.
Calling the Sort Imports command manually inside the UI works flawlessly, so I've tried to instead do:
However this has no effect, probably because python.sortImports is not properly identified as a valid code action to trigger (?). Maybe it's a bug.
We can still make this work though. Using the multicommand extension we can define a "Save File" command targetting python files in which we call the "Sort Imports" beforehand.
Add the following to your settings:
And configure a new keybinding for it that will take precedence over the default save-file command when working on a Python file:
Done! Your imports are sorted properly now and will respect any additional settings :)
By the way, these settings seem to play nicely together with black, which is also supported natively by vscode's python extension:
The better way would be to reuse the exact configuration by pointing vscode to the directory that contains one of the possible config files ( .isort.cfg , tox.ini , setup.cfg ):
TomGrobbe commented Feb 5, 2021
Thanks for this, I was looking to fix the terrible default behavior of organize imports, and your python.sortImports.args section really helped with that.
After experimenting with the editor.codeActionsOnSave some more, this seems to organize the imports on save without having to make a custom command:
GBrachetta commented Feb 7, 2021
Thank you for sharing this! Could you please let me know where can I find all the options available to pass inside "python.sortImports.args" ?
I would love to force the formatter to arrange imports indented and vertically aligned, like so:
But I cannot find the source of this information. Thank you!
cb109 commented Feb 7, 2021
@GBrachetta Those options are taken from the isort CLI which you can get help on via:
GBrachetta commented Feb 7, 2021
Thank you, that helped a lot! :)
den-is commented Nov 27, 2021 •
Hey, thanks for your trials and helpful settings.
I've encountered the very same issue.
Have you opened an issue for that "bug"? I think we should unite and request a fix.
VSCode ignores "python.sortImports": true, key, and for example on the creation of RemoteContainerEnv - completely ignores that setting key in resulting VSCode settings. (i.e. not includes, drops)
Also both blakc and isort can be configured together in a single pyproject.toml in the project's root.
Also potentially with modern isort everything should work without explicitly configuring it but just passing --profile=black to isort.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Читайте также: