未验证 提交 059f2cf4 编写于 作者: L Logan Ramos 提交者: GitHub

Ensure that notebook cell URIs work (#122746)

上级 2285f879
......@@ -7,6 +7,7 @@ import * as assert from 'assert';
import * as glob from 'vs/base/common/glob';
import { sep } from 'vs/base/common/path';
import { isWindows } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
suite('Glob', () => {
......@@ -1019,4 +1020,9 @@ suite('Glob', () => {
assertNoGlobMatch(p, '/DNXConsoleApp/foo/Program.cs');
}
});
test('URI match', () => {
let p = 'scheme:/**/*.md';
assertGlobMatch(p, URI.file('super/duper/long/some/file.md').with({ scheme: 'scheme' }).toString());
});
});
......@@ -37,9 +37,10 @@ import { Lazy } from 'vs/base/common/lazy';
import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
import { NotebookDiffEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookDiffEditorInput';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { ContributedEditorPriority, IEditorAssociationsRegistry, IEditorOverrideService, IEditorType, IEditorTypesHandler } from 'vs/workbench/services/editor/common/editorOverrideService';
import { EditorExtensions } from 'vs/workbench/common/editor';
import { ContributedEditorPriority, DiffEditorInputFactoryFunction, EditorInputFactoryFunction, IEditorAssociationsRegistry, IEditorOverrideService, IEditorType, IEditorTypesHandler } from 'vs/workbench/services/editor/common/editorOverrideService';
import { EditorExtensions, IEditorInput } from 'vs/workbench/common/editor';
import { IFileService } from 'vs/platform/files/common/files';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
export class NotebookProviderInfoStore extends Disposable {
......@@ -129,39 +130,52 @@ export class NotebookProviderInfoStore extends Disposable {
private _registerContributionPoint(notebookProviderInfo: NotebookProviderInfo): void {
for (const selector of notebookProviderInfo.selectors) {
const globPattern = (selector as INotebookExclusiveDocumentFilter).include || selector as glob.IRelativePattern | string;
const notebookEditorInfo = {
id: notebookProviderInfo.id,
label: notebookProviderInfo.displayName,
detail: notebookProviderInfo.providerDisplayName,
describes: (currentEditor: IEditorInput) => currentEditor instanceof NotebookEditorInput && currentEditor.viewType === notebookProviderInfo.id,
priority: notebookProviderInfo.exclusive ? ContributedEditorPriority.exclusive : notebookProviderInfo.priority,
};
const notebookEditorOptions = {
canHandleDiff: () => !!this._configurationService.getValue(NotebookTextDiffEditorPreview) && !this._accessibilityService.isScreenReaderOptimized(),
canSupportResource: (resource: URI) => resource.scheme === Schemas.untitled || resource.scheme === Schemas.vscodeNotebookCell || this._fileService.canHandleResource(resource)
};
const notebookEditorInputFactory: EditorInputFactoryFunction = (resource, options, group) => {
const data = CellUri.parse(resource);
let notebookUri: URI = resource;
let cellOptions: IResourceEditorInput | undefined;
if (data) {
notebookUri = data.notebook;
cellOptions = { resource: resource };
}
const notebookOptions = new NotebookEditorOptions({ ...options, cellOptions });
return { editor: NotebookEditorInput.create(this._instantiationService, notebookUri, notebookProviderInfo.id), options: notebookOptions };
};
const notebookEditorDiffFactory: DiffEditorInputFactoryFunction = (diffEditorInput: DiffEditorInput, options, group) => {
const modifiedInput = diffEditorInput.modifiedInput;
const originalInput = diffEditorInput.originalInput;
const notebookUri = modifiedInput.resource!;
const originalNotebookUri = originalInput.resource!;
return { editor: NotebookDiffEditorInput.create(this._instantiationService, notebookUri, modifiedInput.getName(), originalNotebookUri, originalInput.getName(), diffEditorInput.getName(), notebookProviderInfo.id) };
};
// Register the notebook editor
this._contributedEditorDisposables.add(this._editorOverrideService.registerContributionPoint(
globPattern,
{
id: notebookProviderInfo.id,
label: notebookProviderInfo.displayName,
detail: notebookProviderInfo.providerDisplayName,
describes: (currentEditor) => currentEditor instanceof NotebookEditorInput && currentEditor.viewType === notebookProviderInfo.id,
priority: notebookProviderInfo.exclusive ? ContributedEditorPriority.exclusive : notebookProviderInfo.priority,
},
{
canHandleDiff: () => !!this._configurationService.getValue(NotebookTextDiffEditorPreview) && !this._accessibilityService.isScreenReaderOptimized(),
canSupportResource: resource => resource.scheme === Schemas.untitled || resource.scheme === Schemas.vscodeNotebookCell || this._fileService.canHandleResource(resource)
},
(resource, options, group) => {
const data = CellUri.parse(resource);
let notebookUri: URI = resource;
let cellOptions: IResourceEditorInput | undefined;
if (data) {
notebookUri = data.notebook;
cellOptions = { resource: resource };
}
const notebookOptions = new NotebookEditorOptions({ ...options, cellOptions });
return { editor: NotebookEditorInput.create(this._instantiationService, notebookUri, notebookProviderInfo.id), options: notebookOptions };
},
(diffEditorInput, group) => {
const modifiedInput = diffEditorInput.modifiedInput;
const originalInput = diffEditorInput.originalInput;
const notebookUri = modifiedInput.resource!;
const originalNotebookUri = originalInput.resource!;
return { editor: NotebookDiffEditorInput.create(this._instantiationService, notebookUri, modifiedInput.getName(), originalNotebookUri, originalInput.getName(), diffEditorInput.getName(), notebookProviderInfo.id) };
}
notebookEditorInfo,
notebookEditorOptions,
notebookEditorInputFactory,
notebookEditorDiffFactory
));
// Then register the schema handler as exclusive for that notebook
this._contributedEditorDisposables.add(this._editorOverrideService.registerContributionPoint(
`${Schemas.vscodeNotebookCell}:/**/${globPattern}`,
{ ...notebookEditorInfo, priority: ContributedEditorPriority.exclusive },
notebookEditorOptions,
notebookEditorInputFactory,
notebookEditorDiffFactory
));
}
}
......
......@@ -226,8 +226,10 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
const associationsFromSetting = this.getAssociationsForResource(resource);
// We only want built-in+ if no user defined setting is found, else we won't override
const possibleContributionPoints = contributionPoints.filter(contribPoint => priorityToRank(contribPoint.editorInfo.priority) >= priorityToRank(ContributedEditorPriority.builtin) && contribPoint.editorInfo.id !== DEFAULT_EDITOR_ASSOCIATION.id);
// If the user has a setting we use that, else choose the highest priority editor that is built-in+
const selectedViewType = associationsFromSetting[0]?.viewType || possibleContributionPoints[0]?.editorInfo.id;
// If the contribution is exclusive we use that, else use the user setting, else use the built-in+ contribution
const selectedViewType = possibleContributionPoints[0]?.editorInfo.priority === ContributedEditorPriority.exclusive ?
possibleContributionPoints[0]?.editorInfo.id :
associationsFromSetting[0]?.viewType || possibleContributionPoints[0]?.editorInfo.id;
let conflictingDefault = false;
if (associationsFromSetting.length === 0 && possibleContributionPoints.length > 1) {
......
......@@ -260,7 +260,7 @@ export function globMatchesResource(globPattern: string | glob.IRelativePattern,
return false;
}
const matchOnPath = typeof globPattern === 'string' && globPattern.indexOf(posix.sep) >= 0;
const target = matchOnPath ? resource.path : basename(resource);
const target = matchOnPath ? `${resource.scheme}:${resource.path}` : basename(resource);
return glob.match(globPattern, target.toLowerCase());
}
//#endregion
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册