From 528b473dba12e696213c747f3b710981cd32d30d Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 25 Sep 2020 08:53:37 +0200 Subject: [PATCH] debt - use network.Scheme.file in more places --- src/vs/code/electron-main/window.ts | 3 ++- src/vs/platform/diagnostics/node/diagnosticsService.ts | 5 +++-- src/vs/workbench/contrib/debug/common/debugUtils.ts | 3 ++- .../extensions/electron-browser/runtimeExtensionsEditor.ts | 2 +- src/vs/workbench/contrib/search/common/searchModel.ts | 7 ++++--- .../workbench/contrib/tasks/browser/terminalTaskSystem.ts | 2 +- .../contrib/terminal/browser/links/terminalLinkManager.ts | 2 +- .../terminal/browser/links/terminalProtocolLinkProvider.ts | 3 ++- .../workbench/contrib/terminal/browser/terminalActions.ts | 2 +- .../contrib/themes/browser/themes.test.contribution.ts | 3 ++- src/vs/workbench/contrib/timeline/browser/timelinePane.ts | 2 +- src/vs/workbench/services/path/common/pathService.ts | 4 ++-- src/vs/workbench/services/search/common/searchService.ts | 6 +++--- .../workbench/services/search/common/textSearchManager.ts | 3 ++- src/vs/workbench/test/browser/workbenchTestServices.ts | 4 ++-- 15 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 1de5a852e06..17dcfd5a97b 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -36,6 +36,7 @@ import { IStorageMainService } from 'vs/platform/storage/node/storageMainService import { IFileService } from 'vs/platform/files/common/files'; import { ColorScheme } from 'vs/platform/theme/common/theme'; import { getPathFromAmdModule } from 'vs/base/common/amd'; +import { Schemas } from 'vs/base/common/network'; export interface IWindowCreationOptions { state: IWindowState; @@ -1291,7 +1292,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { private createTouchBarGroupSegments(items: ISerializableCommandAction[] = []): ITouchBarSegment[] { const segments: ITouchBarSegment[] = items.map(item => { let icon: NativeImage | undefined; - if (item.icon && !ThemeIcon.isThemeIcon(item.icon) && item.icon?.dark?.scheme === 'file') { + if (item.icon && !ThemeIcon.isThemeIcon(item.icon) && item.icon?.dark?.scheme === Schemas.file) { icon = nativeImage.createFromPath(URI.revive(item.icon.dark).fsPath); if (icon.isEmpty()) { icon = undefined; diff --git a/src/vs/platform/diagnostics/node/diagnosticsService.ts b/src/vs/platform/diagnostics/node/diagnosticsService.ts index b441b1f0e98..b6f87cc08e9 100644 --- a/src/vs/platform/diagnostics/node/diagnosticsService.ts +++ b/src/vs/platform/diagnostics/node/diagnosticsService.ts @@ -17,6 +17,7 @@ import { IMainProcessInfo } from 'vs/platform/launch/node/launch'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { Iterable } from 'vs/base/common/iterator'; +import { Schemas } from 'vs/base/common/network'; export const ID = 'diagnosticsService'; export const IDiagnosticsService = createDecorator(ID); @@ -450,7 +451,7 @@ export class DiagnosticsService implements IDiagnosticsService { window.folderURIs.forEach(uriComponents => { const folderUri = URI.revive(uriComponents); - if (folderUri.scheme === 'file') { + if (folderUri.scheme === Schemas.file) { const folder = folderUri.fsPath; workspaceStatPromises.push(collectWorkspaceStats(folder, ['node_modules', '.git']).then(stats => { let countMessage = `${stats.fileCount} files`; @@ -518,7 +519,7 @@ export class DiagnosticsService implements IDiagnosticsService { public async reportWorkspaceStats(workspace: IWorkspaceInformation): Promise { for (const { uri } of workspace.folders) { const folderUri = URI.revive(uri); - if (folderUri.scheme !== 'file') { + if (folderUri.scheme !== Schemas.file) { continue; } diff --git a/src/vs/workbench/contrib/debug/common/debugUtils.ts b/src/vs/workbench/contrib/debug/common/debugUtils.ts index 7e7e887a60e..9d4fa4ce1ef 100644 --- a/src/vs/workbench/contrib/debug/common/debugUtils.ts +++ b/src/vs/workbench/contrib/debug/common/debugUtils.ts @@ -8,6 +8,7 @@ import { IDebuggerContribution, IDebugSession, IConfigPresentation } from 'vs/wo import { URI as uri } from 'vs/base/common/uri'; import { isAbsolute } from 'vs/base/common/path'; import { deepClone } from 'vs/base/common/objects'; +import { Schemas } from 'vs/base/common/network'; const _formatPIIRegexp = /{([^}]+)}/g; @@ -145,7 +146,7 @@ function uriToString(source: PathContainer): string | undefined { if (typeof source.path === 'object') { const u = uri.revive(source.path); if (u) { - if (u.scheme === 'file') { + if (u.scheme === Schemas.file) { return u.fsPath; } else { return u.toString(); diff --git a/src/vs/workbench/contrib/extensions/electron-browser/runtimeExtensionsEditor.ts b/src/vs/workbench/contrib/extensions/electron-browser/runtimeExtensionsEditor.ts index 5b1e7777be3..1ce0f3a7aaa 100644 --- a/src/vs/workbench/contrib/extensions/electron-browser/runtimeExtensionsEditor.ts +++ b/src/vs/workbench/contrib/extensions/electron-browser/runtimeExtensionsEditor.ts @@ -424,7 +424,7 @@ export class RuntimeExtensionsEditor extends EditorPane { data.msgContainer.appendChild(el); } - if (element.description.extensionLocation.scheme !== 'file') { + if (element.description.extensionLocation.scheme !== Schemas.file) { const el = $('span', undefined, ...renderCodicons(`$(remote) ${element.description.extensionLocation.authority}`)); data.msgContainer.appendChild(el); diff --git a/src/vs/workbench/contrib/search/common/searchModel.ts b/src/vs/workbench/contrib/search/common/searchModel.ts index e6c24ce8689..0c6e0d19457 100644 --- a/src/vs/workbench/contrib/search/common/searchModel.ts +++ b/src/vs/workbench/contrib/search/common/searchModel.ts @@ -30,6 +30,7 @@ import { memoize } from 'vs/base/common/decorators'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { compareFileNames, compareFileExtensions, comparePaths } from 'vs/base/common/comparers'; import { IFileService, IFileStatWithMetadata } from 'vs/platform/files/common/files'; +import { Schemas } from 'vs/base/common/network'; export class Match { @@ -1106,9 +1107,9 @@ export class SearchModel extends Disposable { const stats = completed && completed.stats as ITextSearchStats; - const fileSchemeOnly = this._searchQuery.folderQueries.every(fq => fq.folder.scheme === 'file'); - const otherSchemeOnly = this._searchQuery.folderQueries.every(fq => fq.folder.scheme !== 'file'); - const scheme = fileSchemeOnly ? 'file' : + const fileSchemeOnly = this._searchQuery.folderQueries.every(fq => fq.folder.scheme === Schemas.file); + const otherSchemeOnly = this._searchQuery.folderQueries.every(fq => fq.folder.scheme !== Schemas.file); + const scheme = fileSchemeOnly ? Schemas.file : otherSchemeOnly ? 'other' : 'mixed'; diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index d0bf98e6663..a73e2f7d2f3 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -1075,7 +1075,7 @@ export class TerminalTaskSystem implements ITaskSystem { if (options.cwd) { let cwd = options.cwd; if (!path.isAbsolute(cwd)) { - if (workspaceFolder && (workspaceFolder.uri.scheme === 'file')) { + if (workspaceFolder && (workspaceFolder.uri.scheme === Schemas.file)) { cwd = path.join(workspaceFolder.uri.fsPath, cwd); } } diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts index c3b990985fe..c2a23641883 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts @@ -191,7 +191,7 @@ export class TerminalLinkManager extends DisposableStore { // Check if it's a file:/// link, hand off to local link handler so to open an editor and // respect line/col attachment const uri = URI.parse(link); - if (uri.scheme === 'file') { + if (uri.scheme === Schemas.file) { this._handleLocalLink(uri.fsPath); return; } diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts index 92a756b5ab9..69251bcd511 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts @@ -10,6 +10,7 @@ import { TerminalLink, OPEN_FILE_LABEL } from 'vs/workbench/contrib/terminal/bro import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { URI } from 'vs/base/common/uri'; import { TerminalBaseLinkProvider } from 'vs/workbench/contrib/terminal/browser/links/terminalBaseLinkProvider'; +import { Schemas } from 'vs/base/common/network'; export class TerminalProtocolLinkProvider extends TerminalBaseLinkProvider { private _linkComputerTarget: ILinkComputerTarget | undefined; @@ -51,7 +52,7 @@ export class TerminalProtocolLinkProvider extends TerminalBaseLinkProvider { const uri = link.url ? (typeof link.url === 'string' ? URI.parse(link.url) : link.url) : undefined; - const label = (uri?.scheme === 'file') ? OPEN_FILE_LABEL : undefined; + const label = (uri?.scheme === Schemas.file) ? OPEN_FILE_LABEL : undefined; return this._instantiationService.createInstance(TerminalLink, this._xterm, range, link.url?.toString() || '', this._xterm.buffer.active.viewportY, this._activateCallback, this._tooltipCallback, true, label); }); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts index 363c3a00542..002bfbabf9c 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts @@ -692,7 +692,7 @@ export function registerTerminalActions() { } const uri = editor.getModel().uri; - if (uri.scheme !== 'file') { + if (uri.scheme !== Schemas.file) { notificationService.warn(localize('workbench.action.terminal.runActiveFile.noFile', 'Only files on disk can be run in the terminal')); return; } diff --git a/src/vs/workbench/contrib/themes/browser/themes.test.contribution.ts b/src/vs/workbench/contrib/themes/browser/themes.test.contribution.ts index 56d449979f5..ec65ff33089 100644 --- a/src/vs/workbench/contrib/themes/browser/themes.test.contribution.ts +++ b/src/vs/workbench/contrib/themes/browser/themes.test.contribution.ts @@ -17,6 +17,7 @@ import { ThemeRule, findMatchingThemeRule } from 'vs/workbench/services/textMate import { Color } from 'vs/base/common/color'; import { IFileService } from 'vs/platform/files/common/files'; import { basename } from 'vs/base/common/resources'; +import { Schemas } from 'vs/base/common/network'; interface IToken { c: string; @@ -244,7 +245,7 @@ CommandsRegistry.registerCommand('_workbench.captureSyntaxTokens', function (acc if (!resource) { const editorService = accessor.get(IEditorService); - const file = editorService.activeEditor ? toResource(editorService.activeEditor, { filterByScheme: 'file' }) : null; + const file = editorService.activeEditor ? toResource(editorService.activeEditor, { filterByScheme: Schemas.file }) : null; if (file) { process(file).then(result => { console.log(result); diff --git a/src/vs/workbench/contrib/timeline/browser/timelinePane.ts b/src/vs/workbench/contrib/timeline/browser/timelinePane.ts index 5eab72c696f..8b451fb7281 100644 --- a/src/vs/workbench/contrib/timeline/browser/timelinePane.ts +++ b/src/vs/workbench/contrib/timeline/browser/timelinePane.ts @@ -352,7 +352,7 @@ export class TimelinePane extends ViewPane { if ((uri?.toString(true) === this.uri?.toString(true) && uri !== undefined) || // Fallback to match on fsPath if we are dealing with files or git schemes - (uri?.fsPath === this.uri?.fsPath && (uri?.scheme === 'file' || uri?.scheme === 'git') && (this.uri?.scheme === 'file' || this.uri?.scheme === 'git'))) { + (uri?.fsPath === this.uri?.fsPath && (uri?.scheme === Schemas.file || uri?.scheme === 'git') && (this.uri?.scheme === Schemas.file || this.uri?.scheme === 'git'))) { // If the uri hasn't changed, make sure we have valid caches for (const source of this.timelineService.getSources()) { diff --git a/src/vs/workbench/services/path/common/pathService.ts b/src/vs/workbench/services/path/common/pathService.ts index 851d03fb66c..66220d241c3 100644 --- a/src/vs/workbench/services/path/common/pathService.ts +++ b/src/vs/workbench/services/path/common/pathService.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { Schemas } from 'vs/base/common/network'; import { IPath, win32, posix } from 'vs/base/common/path'; import { OperatingSystem, OS } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; @@ -132,9 +133,8 @@ export abstract class AbstractPathService implements IPathService { } } - // return new _URI('file', authority, path, '', ''); return URI.from({ - scheme: 'file', + scheme: Schemas.file, authority, path: _path, query: '', diff --git a/src/vs/workbench/services/search/common/searchService.ts b/src/vs/workbench/services/search/common/searchService.ts index cb047264d05..2a6c5dc58ab 100644 --- a/src/vs/workbench/services/search/common/searchService.ts +++ b/src/vs/workbench/services/search/common/searchService.ts @@ -282,9 +282,9 @@ export class SearchService extends Disposable implements ISearchService { } private sendTelemetry(query: ISearchQuery, endToEndTime: number, complete?: ISearchComplete, err?: SearchError): void { - const fileSchemeOnly = query.folderQueries.every(fq => fq.folder.scheme === 'file'); - const otherSchemeOnly = query.folderQueries.every(fq => fq.folder.scheme !== 'file'); - const scheme = fileSchemeOnly ? 'file' : + const fileSchemeOnly = query.folderQueries.every(fq => fq.folder.scheme === Schemas.file); + const otherSchemeOnly = query.folderQueries.every(fq => fq.folder.scheme !== Schemas.file); + const scheme = fileSchemeOnly ? Schemas.file : otherSchemeOnly ? 'other' : 'mixed'; diff --git a/src/vs/workbench/services/search/common/textSearchManager.ts b/src/vs/workbench/services/search/common/textSearchManager.ts index 4913240ba05..03daa687908 100644 --- a/src/vs/workbench/services/search/common/textSearchManager.ts +++ b/src/vs/workbench/services/search/common/textSearchManager.ts @@ -13,6 +13,7 @@ import { URI } from 'vs/base/common/uri'; import { IExtendedExtensionSearchOptions, IFileMatch, IFolderQuery, IPatternInfo, ISearchCompleteStats, ITextQuery, ITextSearchContext, ITextSearchMatch, ITextSearchResult, QueryGlobTester, resolvePatternsForProvider } from 'vs/workbench/services/search/common/search'; import { TextSearchProvider, TextSearchResult, TextSearchMatch, TextSearchComplete, Range, TextSearchOptions, TextSearchQuery } from 'vs/workbench/services/search/common/searchExtTypes'; import { nextTick } from 'vs/base/common/process'; +import { Schemas } from 'vs/base/common/network'; export interface IFileUtils { readdir: (resource: URI) => Promise; @@ -117,7 +118,7 @@ export class TextSearchManager { return; } - const hasSibling = folderQuery.folder.scheme === 'file' ? + const hasSibling = folderQuery.folder.scheme === Schemas.file ? glob.hasSiblingPromiseFn(() => { return this.fileUtils.readdir(resources.dirname(result.uri)); }) : diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index a6acd6fcaf5..3527de197e4 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -852,10 +852,10 @@ export class TestFileService implements IFileService { } activateProvider(_scheme: string): Promise { throw new Error('not implemented'); } - canHandleResource(resource: URI): boolean { return resource.scheme === 'file' || this.providers.has(resource.scheme); } + canHandleResource(resource: URI): boolean { return resource.scheme === Schemas.file || this.providers.has(resource.scheme); } listCapabilities() { return [ - { scheme: 'file', capabilities: FileSystemProviderCapabilities.FileOpenReadWriteClose }, + { scheme: Schemas.file, capabilities: FileSystemProviderCapabilities.FileOpenReadWriteClose }, ...Iterable.map(this.providers, ([scheme, p]) => { return { scheme, capabilities: p.capabilities }; }) ]; }