forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspace.ts
More file actions
91 lines (88 loc) · 3.38 KB
/
workspace.ts
File metadata and controls
91 lines (88 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { injectable } from 'inversify';
import * as path from 'path';
import {
CancellationToken,
ConfigurationChangeEvent,
Event,
FileSystemWatcher,
GlobPattern,
Uri,
workspace,
WorkspaceConfiguration,
WorkspaceFolder,
WorkspaceFoldersChangeEvent,
} from 'vscode';
import { Resource } from '../types';
import { getOSType, OSType } from '../utils/platform';
import { IWorkspaceService } from './types';
@injectable()
export class WorkspaceService implements IWorkspaceService {
public get onDidChangeConfiguration(): Event<ConfigurationChangeEvent> {
return workspace.onDidChangeConfiguration;
}
public get rootPath(): string | undefined {
return Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0
? workspace.workspaceFolders[0].uri.fsPath
: undefined;
}
public get workspaceFolders(): readonly WorkspaceFolder[] | undefined {
return workspace.workspaceFolders;
}
public get onDidChangeWorkspaceFolders(): Event<WorkspaceFoldersChangeEvent> {
return workspace.onDidChangeWorkspaceFolders;
}
public get hasWorkspaceFolders() {
return Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0;
}
public get workspaceFile() {
return workspace.workspaceFile;
}
public getConfiguration(section?: string, resource?: Uri): WorkspaceConfiguration {
return workspace.getConfiguration(section, resource || null);
}
public getWorkspaceFolder(uri: Resource): WorkspaceFolder | undefined {
return uri ? workspace.getWorkspaceFolder(uri) : undefined;
}
public asRelativePath(pathOrUri: string | Uri, includeWorkspaceFolder?: boolean): string {
return workspace.asRelativePath(pathOrUri, includeWorkspaceFolder);
}
public createFileSystemWatcher(
globPattern: GlobPattern,
ignoreCreateEvents?: boolean,
ignoreChangeEvents?: boolean,
ignoreDeleteEvents?: boolean,
): FileSystemWatcher {
return workspace.createFileSystemWatcher(
globPattern,
ignoreCreateEvents,
ignoreChangeEvents,
ignoreDeleteEvents,
);
}
public findFiles(
include: GlobPattern,
exclude?: GlobPattern,
maxResults?: number,
token?: CancellationToken,
): Thenable<Uri[]> {
const excludePattern = exclude === undefined ? this.searchExcludes : exclude;
return workspace.findFiles(include, excludePattern, maxResults, token);
}
public getWorkspaceFolderIdentifier(resource: Resource, defaultValue: string = ''): string {
const workspaceFolder = resource ? workspace.getWorkspaceFolder(resource) : undefined;
return workspaceFolder
? path.normalize(
getOSType() === OSType.Windows
? workspaceFolder.uri.fsPath.toUpperCase()
: workspaceFolder.uri.fsPath,
)
: defaultValue;
}
private get searchExcludes() {
const searchExcludes = this.getConfiguration('search.exclude');
const enabledSearchExcludes = Object.keys(searchExcludes).filter((key) => searchExcludes.get(key) === true);
return `{${enabledSearchExcludes.join(',')}}`;
}
}