mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
debt - change glob to not require paths.relative anymore
This commit is contained in:
@@ -55,6 +55,7 @@ import { ExtHostDialogs } from 'vs/workbench/api/node/extHostDialogs';
|
||||
import { ExtHostFileSystem } from 'vs/workbench/api/node/extHostFileSystem';
|
||||
import { FileChangeType, FileType } from 'vs/platform/files/common/files';
|
||||
import { ExtHostDecorations } from 'vs/workbench/api/node/extHostDecorations';
|
||||
import { toGlobPattern, toLanguageSelector } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
|
||||
export interface IExtensionApiFactory {
|
||||
(extension: IExtensionDescription): typeof vscode;
|
||||
@@ -216,7 +217,7 @@ export function createApiFactory(
|
||||
return extHostLanguages.getLanguages();
|
||||
},
|
||||
match(selector: vscode.DocumentSelector, document: vscode.TextDocument): number {
|
||||
return score(selector, <any>document.uri, document.languageId);
|
||||
return score(toLanguageSelector(selector), <any>document.uri, document.languageId);
|
||||
},
|
||||
registerCodeActionsProvider(selector: vscode.DocumentSelector, provider: vscode.CodeActionProvider): vscode.Disposable {
|
||||
return languageFeatures.registerCodeActionProvider(selector, provider);
|
||||
@@ -408,7 +409,7 @@ export function createApiFactory(
|
||||
return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
|
||||
},
|
||||
findFiles: (include, exclude, maxResults?, token?) => {
|
||||
return extHostWorkspace.findFiles(include, exclude, maxResults, token);
|
||||
return extHostWorkspace.findFiles(toGlobPattern(include), toGlobPattern(exclude), maxResults, token);
|
||||
},
|
||||
saveAll: (includeUntitled?) => {
|
||||
return extHostWorkspace.saveAll(includeUntitled);
|
||||
@@ -417,7 +418,7 @@ export function createApiFactory(
|
||||
return extHostEditors.applyWorkspaceEdit(edit);
|
||||
},
|
||||
createFileSystemWatcher: (pattern, ignoreCreate, ignoreChange, ignoreDelete): vscode.FileSystemWatcher => {
|
||||
return extHostFileSystemEvent.createFileSystemWatcher(pattern, ignoreCreate, ignoreChange, ignoreDelete);
|
||||
return extHostFileSystemEvent.createFileSystemWatcher(toGlobPattern(pattern), ignoreCreate, ignoreChange, ignoreDelete);
|
||||
},
|
||||
get textDocuments() {
|
||||
return extHostDocuments.getAllDocumentData().map(data => data.document);
|
||||
|
||||
@@ -17,6 +17,8 @@ import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import { ISelection } from 'vs/editor/common/core/selection';
|
||||
import * as htmlContent from 'vs/base/common/htmlContent';
|
||||
import { IRelativePattern, isRelativePattern } from 'vs/base/common/glob';
|
||||
import { LanguageSelector, LanguageFilter } from 'vs/editor/common/modes/languageSelector';
|
||||
|
||||
export interface PositionLike {
|
||||
line: number;
|
||||
@@ -583,4 +585,36 @@ export function toTextEditorOptions(options?: vscode.TextDocumentShowOptions): I
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function toGlobPattern(pattern: vscode.GlobPattern): string | IRelativePattern {
|
||||
if (typeof pattern === 'string') {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
if (!isRelativePattern(pattern)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return new types.RelativePattern(pattern.base, pattern.pattern);
|
||||
}
|
||||
|
||||
export function toLanguageSelector(selector: vscode.DocumentSelector): LanguageSelector {
|
||||
if (Array.isArray(selector)) {
|
||||
return selector.map(sel => doToLanguageSelector(sel));
|
||||
}
|
||||
|
||||
return doToLanguageSelector(selector);
|
||||
}
|
||||
|
||||
function doToLanguageSelector(selector: string | vscode.DocumentFilter): string | LanguageFilter {
|
||||
if (typeof selector === 'string') {
|
||||
return selector;
|
||||
}
|
||||
|
||||
return {
|
||||
language: selector.language,
|
||||
scheme: selector.scheme,
|
||||
pattern: toGlobPattern(selector.pattern)
|
||||
};
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { illegalArgument } from 'vs/base/common/errors';
|
||||
import * as vscode from 'vscode';
|
||||
import { isMarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { IRelativePattern } from 'vs/base/common/glob';
|
||||
import { relative } from 'path';
|
||||
|
||||
export class Disposable {
|
||||
|
||||
@@ -1492,4 +1493,8 @@ export class RelativePattern implements IRelativePattern {
|
||||
this.base = typeof base === 'string' ? base : base.uri.fsPath;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public pathToRelative(from: string, to: string): string {
|
||||
return relative(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user