mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Implemented new setting "pyright.disableOrganizeImports".
This commit is contained in:
parent
b9f291afc3
commit
a0b48358f5
@ -93,6 +93,12 @@
|
||||
"description": "Disables type completion, definitions, and references.",
|
||||
"scope": "resource"
|
||||
},
|
||||
"pyright.disableOrganizeImports": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Disables the “Organize Imports” command.",
|
||||
"scope": "resource"
|
||||
},
|
||||
"pyright.openFilesOnly": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
|
@ -4,6 +4,8 @@ The Pyright VS Code extension honors the following settings.
|
||||
|
||||
**pyright.disableLanguageServices** [boolean]: Disables all language services except for “hover”. This includes type completion, signature completion, find definition, find references, and find symbols in file. This option is useful if you want to use pyright only as a type checker but want to run another Python language server for langue service features.
|
||||
|
||||
**pyright.disableOrganizeImports** [boolean]: Disables the “Organize Imports” command. This is useful if you are using another extension that provides similar functionality and you don’t want the two extensions to fight each other.
|
||||
|
||||
**pyright.openFilesOnly** [boolean]: Determines whether pyright analyzes (and reports errors for) all files in the workspace, as indicated by the config file. If this option is set to true, pyright analyzes only open files.
|
||||
|
||||
**pyright.typeCheckingMode** ["off", "basic", "strict"]: Determines the default type-checking level used by pyright. This can be overridden in the configuration file.
|
||||
|
@ -31,6 +31,7 @@ export class CreateTypeStubCommand implements ServerCommand {
|
||||
rootUri: convertPathToUri(workspaceRoot),
|
||||
serviceInstance: service,
|
||||
disableLanguageServices: true,
|
||||
disableOrganizeImports: true,
|
||||
};
|
||||
|
||||
service.setCompletionCallback((results) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* createTypeStub.ts
|
||||
* quickActionCommand.ts
|
||||
*
|
||||
* Implements command that maps to a quick action.
|
||||
*/
|
||||
@ -9,6 +9,7 @@ import { CancellationToken, ExecuteCommandParams, TextEdit } from 'vscode-langua
|
||||
import { convertUriToPath } from '../common/pathUtils';
|
||||
import { LanguageServerInterface } from '../languageServerBase';
|
||||
import { ServerCommand } from './commandController';
|
||||
import { Commands } from './commands';
|
||||
|
||||
export class QuickActionCommand implements ServerCommand {
|
||||
constructor(private _ls: LanguageServerInterface) {}
|
||||
@ -19,6 +20,11 @@ export class QuickActionCommand implements ServerCommand {
|
||||
const otherArgs = params.arguments.slice(1);
|
||||
const filePath = convertUriToPath(docUri);
|
||||
const workspace = this._ls.getWorkspaceForFile(filePath);
|
||||
|
||||
if (params.command === Commands.orderImports && workspace.disableOrganizeImports) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const editActions = workspace.serviceInstance.performQuickAction(
|
||||
filePath,
|
||||
params.command,
|
||||
|
@ -70,6 +70,7 @@ export interface ServerSettings {
|
||||
typeCheckingMode?: string;
|
||||
useLibraryCodeForTypes?: boolean;
|
||||
disableLanguageServices?: boolean;
|
||||
disableOrganizeImports?: boolean;
|
||||
autoSearchPaths?: boolean;
|
||||
watchForLibraryChanges?: boolean;
|
||||
}
|
||||
@ -80,6 +81,7 @@ export interface WorkspaceServiceInstance {
|
||||
rootUri: string;
|
||||
serviceInstance: AnalyzerService;
|
||||
disableLanguageServices: boolean;
|
||||
disableOrganizeImports: boolean;
|
||||
}
|
||||
|
||||
export interface WindowInterface {
|
||||
@ -152,6 +154,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
|
||||
params: CodeActionParams,
|
||||
token: CancellationToken
|
||||
): Promise<(Command | CodeAction)[] | undefined | null>;
|
||||
|
||||
abstract async getSettings(workspace: WorkspaceServiceInstance): Promise<ServerSettings>;
|
||||
|
||||
protected getConfiguration(workspace: WorkspaceServiceInstance, section: string) {
|
||||
@ -296,6 +299,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
|
||||
rootUri: folder.uri,
|
||||
serviceInstance: this.createAnalyzerService(folder.name),
|
||||
disableLanguageServices: false,
|
||||
disableOrganizeImports: false,
|
||||
});
|
||||
});
|
||||
} else if (params.rootPath) {
|
||||
@ -305,6 +309,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
|
||||
rootUri: '',
|
||||
serviceInstance: this.createAnalyzerService(params.rootPath),
|
||||
disableLanguageServices: false,
|
||||
disableOrganizeImports: false,
|
||||
});
|
||||
}
|
||||
|
||||
@ -604,6 +609,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
|
||||
rootUri: workspace.uri,
|
||||
serviceInstance: this.createAnalyzerService(workspace.name),
|
||||
disableLanguageServices: false,
|
||||
disableOrganizeImports: false,
|
||||
};
|
||||
this._workspaceMap.set(rootPath, newWorkspace);
|
||||
await this.updateSettingsForWorkspace(newWorkspace);
|
||||
@ -675,6 +681,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
|
||||
const serverSettings = await this.getSettings(workspace);
|
||||
this.updateOptionsAndRestartService(workspace, serverSettings);
|
||||
workspace.disableLanguageServices = !!serverSettings.disableLanguageServices;
|
||||
workspace.disableOrganizeImports = !!serverSettings.disableOrganizeImports;
|
||||
}
|
||||
|
||||
updateOptionsAndRestartService(
|
||||
|
@ -26,7 +26,11 @@ export class CodeActionProvider {
|
||||
Command.create('Organize Imports', Commands.orderImports),
|
||||
CodeActionKind.SourceOrganizeImports
|
||||
);
|
||||
const codeActions: CodeAction[] = [sortImportsCodeAction];
|
||||
const codeActions: CodeAction[] = [];
|
||||
|
||||
if (!workspace.disableOrganizeImports) {
|
||||
codeActions.push(sortImportsCodeAction);
|
||||
}
|
||||
|
||||
if (!workspace.disableLanguageServices) {
|
||||
const diags = workspace.serviceInstance.getDiagnosticsForRange(filePath, range);
|
||||
|
@ -46,11 +46,13 @@ class PyrightServer extends LanguageServerBase {
|
||||
serverSettings.openFilesOnly = !!pyrightSection.openFilesOnly;
|
||||
serverSettings.useLibraryCodeForTypes = !!pyrightSection.useLibraryCodeForTypes;
|
||||
serverSettings.disableLanguageServices = !!pyrightSection.disableLanguageServices;
|
||||
serverSettings.disableOrganizeImports = !!pyrightSection.disableOrganizeImports;
|
||||
serverSettings.typeCheckingMode = pyrightSection.typeCheckingMode;
|
||||
} else {
|
||||
serverSettings.openFilesOnly = true;
|
||||
serverSettings.useLibraryCodeForTypes = false;
|
||||
serverSettings.disableLanguageServices = false;
|
||||
serverSettings.disableOrganizeImports = false;
|
||||
serverSettings.typeCheckingMode = undefined;
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -139,6 +139,7 @@ export class TestState {
|
||||
rootUri: convertPathToUri(this.fs.getModulePath()),
|
||||
serviceInstance: service,
|
||||
disableLanguageServices: false,
|
||||
disableOrganizeImports: false,
|
||||
};
|
||||
|
||||
if (this._files.length > 0) {
|
||||
|
@ -63,6 +63,7 @@ export class WorkspaceMap extends Map<string, WorkspaceServiceInstance> {
|
||||
rootUri: '',
|
||||
serviceInstance: this._ls.createAnalyzerService(this._defaultWorkspacePath),
|
||||
disableLanguageServices: false,
|
||||
disableOrganizeImports: false,
|
||||
};
|
||||
this.set(this._defaultWorkspacePath, defaultWorkspace);
|
||||
this._ls.updateSettingsForWorkspace(defaultWorkspace).ignoreErrors();
|
||||
|
Loading…
Reference in New Issue
Block a user