Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quickopen: file url #190304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IPickerQuickAccessItem, PickerQuickAccessProvider, TriggerAction, FastA
import { prepareQuery, IPreparedQuery, compareItemsByFuzzyScore, scoreItemFuzzy, FuzzyScorerCache } from '../../../../base/common/fuzzyScorer.js';
import { IFileQueryBuilderOptions, QueryBuilder } from '../../../services/search/common/queryBuilder.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { getOutOfWorkspaceEditorResources, extractRangeFromFilter, IWorkbenchSearchConfiguration } from '../common/search.js';
import { getOutOfWorkspaceEditorResources, extractRangeFromFileUrl, extractRangeFromFilter, IWorkbenchSearchConfiguration } from '../common/search.js';
import { ISearchService, ISearchComplete } from '../../../services/search/common/search.js';
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
import { untildify } from '../../../../base/common/labels.js';
Expand Down Expand Up @@ -251,7 +251,10 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt

// Find a suitable range from the pattern looking for ":", "#" or ","
// unless we have the `@` editor symbol character inside the filter
const filterWithRange = extractRangeFromFilter(originalFilter, [GotoSymbolQuickAccessProvider.PREFIX]);
const filterWithRange =
// Treat "file://" url as file path with selection
extractRangeFromFileUrl(originalFilter) ??
extractRangeFromFilter(originalFilter, [GotoSymbolQuickAccessProvider.PREFIX]);

// Update filter with normalized values
let filter: string;
Expand Down
26 changes: 26 additions & 0 deletions src/vs/workbench/contrib/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isNumber } from '../../../../base/common/types.js';
import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { compare } from '../../../../base/common/strings.js';
import { groupBy } from '../../../../base/common/arrays.js';
import { extractSelection } from '../../../../platform/opener/common/opener.js';

export interface IWorkspaceSymbol {
name: string;
Expand Down Expand Up @@ -156,6 +157,31 @@ export interface IFilterAndRange {
range: IRange;
}

export function extractRangeFromFileUrl(filter: string): IFilterAndRange | undefined {
if (!filter.startsWith('file://')) {
return undefined;
}
const { uri, selection } = extractSelection(URI.parse(filter));
let range: IRange;
if (selection) {
const { startLineNumber, startColumn, endLineNumber, endColumn } = selection;
range = {
startLineNumber,
startColumn,
endLineNumber: endLineNumber ?? startLineNumber,
endColumn: endColumn ?? startColumn
};
} else {
range = {
startLineNumber: 1,
startColumn: 1,
endLineNumber: 1,
endColumn: 1
};
}
return { filter: uri.fsPath, range };
}

export function extractRangeFromFilter(filter: string, unless?: string[]): IFilterAndRange | undefined {
// Ignore when the unless character not the first character or is before the line colon pattern
if (!filter || unless?.some(value => {
Expand Down