Drop `workspaceService.hasWorkspaceFolders` by FATESAIKOU · Pull Request #14100 · microsoft/vscode-python · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/6237.md
7 changes: 5 additions & 2 deletions src/client/activation/activationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
}
const key = this.getWorkspaceKey(doc.uri);
// If we have opened a doc that does not belong to workspace, then do nothing.
if (key === '' && this.workspaceService.hasWorkspaceFolders) {
if (key === '' && (this.workspaceService.workspaceFolders || []).length > 0) {
return;
}
if (this.activatedWorkspaces.has(key)) {
Expand Down Expand Up @@ -161,7 +161,10 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
this.addRemoveDocOpenedHandlers();
}
protected hasMultipleWorkspaces() {
return this.workspaceService.hasWorkspaceFolders && this.workspaceService.workspaceFolders!.length > 1;
return (
(this.workspaceService.workspaceFolders || []).length > 0 &&
this.workspaceService.workspaceFolders!.length > 1
);
}
protected getWorkspaceKey(resource: Resource) {
return this.workspaceService.getWorkspaceFolderIdentifier(resource, '');
Expand Down
7 changes: 4 additions & 3 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ export class LanguageServerExtensionActivationService
}

private async onDidChangeConfiguration(event: ConfigurationChangeEvent): Promise<void> {
const workspacesUris: (Uri | undefined)[] = this.workspaceService.hasWorkspaceFolders
? this.workspaceService.workspaceFolders!.map((workspace) => workspace.uri)
: [undefined];
const workspacesUris: (Uri | undefined)[] =
(this.workspaceService.workspaceFolders || []).length > 0
? this.workspaceService.workspaceFolders!.map((workspace) => workspace.uri)
: [undefined];
if (
workspacesUris.findIndex((uri) => event.affectsConfiguration(`python.${languageServerSetting}`, uri)) === -1
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class InvalidLaunchJsonDebuggerService extends BaseDiagnosticsService {
);
}
public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
if (!this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length === 0) {
return [];
}
const workspaceFolder = resource
Expand All @@ -84,7 +84,7 @@ export class InvalidLaunchJsonDebuggerService extends BaseDiagnosticsService {
diagnostics.forEach((diagnostic) => this.handleDiagnostic(diagnostic));
}
protected async fixLaunchJson(code: DiagnosticCodes) {
if (!this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length === 0) {
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/client/datascience/interactive-common/notebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ export class NotebookProvider implements INotebookProvider {
// This is required, else using `undefined` as a resource when we have worksapce folders is a different meaning.
// This means interactive window doesn't properly support mult-root workspaces as we pick first workspace.
// Ideally we need to pick the resource of the corresponding Python file.
resource = this.workspaceService.hasWorkspaceFolders
? this.workspaceService.workspaceFolders![0]!.uri
: undefined;
resource =
(this.workspaceService.workspaceFolders || []).length > 0
? this.workspaceService.workspaceFolders![0]!.uri
: undefined;
}
const promise = rawKernel
? this.rawNotebookProvider.createNotebook(
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class JupyterExporter implements INotebookExporter {
if (!haveChangeAlready) {
const notebookFilePath = path.dirname(notebookFile);
// First see if we have a workspace open, this only works if we have a workspace root to be relative to
if (this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length > 0) {
const workspacePath = await this.firstWorkspaceFolder(cells);

// Make sure that we have everything that we need here
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class JupyterImporter implements INotebookImporter {
if (!haveChangeAlready) {
const notebookFilePath = path.dirname(notebookFile.fsPath);
// First see if we have a workspace open, this only works if we have a workspace root to be relative to
if (this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length > 0) {
const workspacePath = this.workspaceService.workspaceFolders![0].uri.fsPath;

// Make sure that we have everything that we need here
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/kernel-launcher/kernelDaemonPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class KernelDaemonPool implements IDisposable {
this.envVars.onDidEnvironmentVariablesChange(this.onDidEnvironmentVariablesChange.bind(this));
this.interrpeterService.onDidChangeInterpreter(this.onDidChangeInterpreter.bind(this));
const promises: Promise<void>[] = [];
if (this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length > 0) {
promises.push(
...(this.workspaceService.workspaceFolders || []).map((item) => this.preWarmKernelDaemon(item.uri))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
config: AttachRequestArguments & DebugConfiguration
): WorkspaceFolder | undefined {
const workspaceFolder = config.workspaceFolder;
if (!this.workspaceService.hasWorkspaceFolders || !workspaceFolder) {
if ((this.workspaceService.workspaceFolders || []).length === 0 || !workspaceFolder) {
return;
}
return this.workspaceService.workspaceFolders!.find((ws) => ws.uri.fsPath === workspaceFolder);
Expand Down
7 changes: 4 additions & 3 deletions src/client/interpreter/virtualEnvs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ export class VirtualEnvironmentManager implements IVirtualEnvironmentManager {
}

private async getWorkspaceRoot(resource?: Uri): Promise<string | undefined> {
const defaultWorkspaceUri = this.workspaceService.hasWorkspaceFolders
? this.workspaceService.workspaceFolders![0].uri
: undefined;
const defaultWorkspaceUri =
(this.workspaceService.workspaceFolders || []).length > 0
? this.workspaceService.workspaceFolders![0].uri
: undefined;
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
const uri = workspaceFolder ? workspaceFolder.uri : defaultWorkspaceUri;
return uri ? uri.fsPath : undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/linterAvailability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class AvailableLinterActivator implements IAvailableLinterActivator {
* @param resource Context information for workspace.
*/
public async isLinterAvailable(linterInfo: ILinterInfo, resource: Resource): Promise<boolean | undefined> {
if (!this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length === 0) {
return false;
}
const workspaceFolder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class CondaService implements ICondaService {
}

private async onDidChangeConfiguration(event: ConfigurationChangeEvent) {
const workspacesUris: (Uri | undefined)[] = this.workspaceService.hasWorkspaceFolders
const workspacesUris: (Uri | undefined)[] = ((this.workspaceService.workspaceFolders || []).length > 0)
? this.workspaceService.workspaceFolders!.map((workspace) => workspace.uri)
: [undefined];
if (workspacesUris.findIndex((uri) => event.affectsConfiguration('python.condaPath', uri)) === -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/testing/common/debugLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class DebugLauncher implements ITestDebugLauncher {
}
}
private resolveWorkspaceFolder(cwd: string): WorkspaceFolder {
if (!this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length === 0) {
throw new Error('Please open a workspace');
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/testing/common/services/configSettingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class TestConfigSettingsService implements ITestConfigSettingsService {
private async updateSetting(testDirectory: string | Uri, setting: string, value: any) {
let pythonConfig: WorkspaceConfiguration;
const resource = typeof testDirectory === 'string' ? Uri.file(testDirectory) : testDirectory;
if (!this.workspaceService.hasWorkspaceFolders) {
if ((this.workspaceService.workspaceFolders || []).length === 0) {
pythonConfig = this.workspaceService.getConfiguration('python');
} else if (this.workspaceService.workspaceFolders!.length === 1) {
pythonConfig = this.workspaceService.getConfiguration(
Expand Down
7 changes: 5 additions & 2 deletions src/client/testing/main.ts