mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
clean up opener and introduce withSelectionFragment method
This commit is contained in:
parent
21a4d0e967
commit
5c833537ec
|
@ -62,7 +62,7 @@ class EditorOpener implements IOpener {
|
|||
if (typeof target === 'string') {
|
||||
target = URI.parse(target);
|
||||
}
|
||||
const selection: { startLineNumber: number; startColumn: number } | undefined = selectionFragment(target);
|
||||
const selection = selectionFragment(target);
|
||||
if (selection) {
|
||||
target = target.with({ fragment: '' });
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
|||
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { equalsIgnoreCase, startsWithIgnoreCase } from 'vs/base/common/strings';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { IEditorOptions, ITextEditorSelection } from 'vs/platform/editor/common/editor';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export const IOpenerService = createDecorator<IOpenerService>('openerService');
|
||||
|
@ -137,6 +137,10 @@ export function matchesSomeScheme(target: URI | string, ...schemes: string[]): b
|
|||
return schemes.some(scheme => matchesScheme(target, scheme));
|
||||
}
|
||||
|
||||
export function withSelectionFragment(uri: URI, selection: ITextEditorSelection): URI {
|
||||
return uri.with({ fragment: `${selection.startLineNumber},${selection.startColumn}${selection.endLineNumber ? `-${selection.endLineNumber}${selection.endColumn ? `,${selection.endColumn}` : ''}` : ''}` });
|
||||
}
|
||||
|
||||
/**
|
||||
* file:///some/file.js#73
|
||||
* file:///some/file.js#L73
|
||||
|
@ -147,18 +151,16 @@ export function matchesSomeScheme(target: URI | string, ...schemes: string[]): b
|
|||
* file:///some/file.js#73,84-83,52
|
||||
* file:///some/file.js#L73,84-L83,52
|
||||
*/
|
||||
export function selectionFragment(target: URI): { startLineNumber: number; startColumn: number; endLineNumber?: number; endColumn?: number } | undefined {
|
||||
let selection: { startLineNumber: number; startColumn: number; endLineNumber?: number; endColumn?: number } | undefined = undefined;
|
||||
export function selectionFragment(target: URI): ITextEditorSelection | undefined {
|
||||
let selection: ITextEditorSelection | undefined = undefined;
|
||||
const match = /^L?(\d+)(?:,(\d+))?(-L?(\d+)(?:,(\d+))?)?/.exec(target.fragment);
|
||||
if (match) {
|
||||
selection = {
|
||||
startLineNumber: parseInt(match[1]),
|
||||
startColumn: match[2] ? parseInt(match[2]) : 1,
|
||||
endLineNumber: match[4] ? parseInt(match[4]) : undefined,
|
||||
endColumn: match[4] ? (match[5] ? parseInt(match[5]) : 1) : undefined
|
||||
};
|
||||
if (match[4]) {
|
||||
selection.endLineNumber = parseInt(match[4]);
|
||||
selection.endColumn = match[5] ? parseInt(match[5]) : 1;
|
||||
}
|
||||
}
|
||||
return selection;
|
||||
}
|
||||
|
|
|
@ -5,28 +5,28 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { selectionFragment } from 'vs/platform/opener/common/opener';
|
||||
import { selectionFragment, withSelectionFragment } from 'vs/platform/opener/common/opener';
|
||||
|
||||
suite('selectionFragment', () => {
|
||||
|
||||
test('get selectionFragment with only startLineNumber', async () => {
|
||||
const uri = URI.parse('file:///some/file.js#73');
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 1 });
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 1, endLineNumber: undefined, endColumn: undefined });
|
||||
});
|
||||
|
||||
test('get selectionFragment with only startLineNumber in L format', async () => {
|
||||
const uri = URI.parse('file:///some/file.js#L73');
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 1 });
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 1, endLineNumber: undefined, endColumn: undefined });
|
||||
});
|
||||
|
||||
test('get selectionFragment with startLineNumber and startColumn', async () => {
|
||||
const uri = URI.parse('file:///some/file.js#73,84');
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 84 });
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 84, endLineNumber: undefined, endColumn: undefined });
|
||||
});
|
||||
|
||||
test('get selectionFragment with startLineNumber and startColumn in L format', async () => {
|
||||
const uri = URI.parse('file:///some/file.js#L73,84');
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 84 });
|
||||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 84, endLineNumber: undefined, endColumn: undefined });
|
||||
});
|
||||
|
||||
test('get selectionFragment with range and no column number', async () => {
|
||||
|
@ -59,4 +59,16 @@ suite('selectionFragment', () => {
|
|||
assert.deepStrictEqual(selectionFragment(uri), { startLineNumber: 73, startColumn: 84, endLineNumber: 83, endColumn: 52 });
|
||||
});
|
||||
|
||||
test('withSelectionFragment with startLineNumber and startColumn', async () => {
|
||||
assert.deepStrictEqual(withSelectionFragment(URI.parse('file:///some/file.js'), { startLineNumber: 73, startColumn: 84 }).toString(), 'file:///some/file.js#73%2C84');
|
||||
});
|
||||
|
||||
test('withSelectionFragment with startLineNumber, startColumn and endLineNumber', async () => {
|
||||
assert.deepStrictEqual(withSelectionFragment(URI.parse('file:///some/file.js'), { startLineNumber: 73, startColumn: 84, endLineNumber: 83 }).toString(), 'file:///some/file.js#73%2C84-83');
|
||||
});
|
||||
|
||||
test('withSelectionFragment with startLineNumber, startColumn and endLineNumber, endColumn', async () => {
|
||||
assert.deepStrictEqual(withSelectionFragment(URI.parse('file:///some/file.js'), { startLineNumber: 73, startColumn: 84, endLineNumber: 83, endColumn: 52 }).toString(), 'file:///some/file.js#73%2C84-83%2C52');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -46,7 +46,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
|
|||
import { editorLightBulbForeground, editorLightBulbAutoFixForeground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPane';
|
||||
import { IViewDescriptorService } from 'vs/workbench/common/views';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { IOpenerService, withSelectionFragment } from 'vs/platform/opener/common/opener';
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
|
||||
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
|
||||
|
@ -397,10 +397,10 @@ export class MarkersView extends ViewPane implements IMarkersView {
|
|||
return element.resource;
|
||||
}
|
||||
if (element instanceof Marker) {
|
||||
return element.resource.with({ fragment: `${element.range.startLineNumber},${element.range.startColumn}-${element.range.endLineNumber},${element.range.endColumn}` });
|
||||
return withSelectionFragment(element.resource, element.range);
|
||||
}
|
||||
if (element instanceof RelatedInformation) {
|
||||
return element.raw.resource.with({ fragment: `${element.raw.startLineNumber},${element.raw.startColumn}-${element.raw.endLineNumber},${element.raw.endColumn}` });
|
||||
return withSelectionFragment(element.raw.resource, element.raw);
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
|
|
|
@ -46,7 +46,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
|
|||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { getSelectionKeyboardEvent, WorkbenchObjectTree } from 'vs/platform/list/browser/listService';
|
||||
import { INotificationService, } from 'vs/platform/notification/common/notification';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { IOpenerService, withSelectionFragment } from 'vs/platform/opener/common/opener';
|
||||
import { IProgress, IProgressService, IProgressStep } from 'vs/platform/progress/common/progress';
|
||||
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
|
@ -730,8 +730,7 @@ export class SearchView extends ViewPane {
|
|||
return element.resource;
|
||||
}
|
||||
if (element instanceof Match) {
|
||||
const range = element.range();
|
||||
return element.parent().resource.with({ fragment: `${range.startLineNumber},${range.startColumn}-${range.endLineNumber},${range.endColumn}` });
|
||||
return withSelectionFragment(element.parent().resource, element.range());
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue