mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode a4177f50c475fc0fa278a78235e3bee9ffdec781 (#8649)
* Merge from vscode a4177f50c475fc0fa278a78235e3bee9ffdec781 * distro * fix tests
This commit is contained in:
@@ -12,9 +12,27 @@ const SEARCH_RESULT_SELECTOR = { language: 'search-result' };
|
||||
const DIRECTIVES = ['# Query:', '# Flags:', '# Including:', '# Excluding:', '# ContextLines:'];
|
||||
const FLAGS = ['RegExp', 'CaseSensitive', 'IgnoreExcludeSettings', 'WordMatch'];
|
||||
|
||||
let cachedLastParse: { version: number, parse: ParsedSearchResults } | undefined;
|
||||
let cachedLastParse: { version: number, parse: ParsedSearchResults, uri: vscode.Uri } | undefined;
|
||||
let documentChangeListener: vscode.Disposable | undefined;
|
||||
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
const contextLineDecorations = vscode.window.createTextEditorDecorationType({ opacity: '0.7' });
|
||||
const matchLineDecorations = vscode.window.createTextEditorDecorationType({ fontWeight: 'bold' });
|
||||
|
||||
const decorate = (editor: vscode.TextEditor) => {
|
||||
const parsed = parseSearchResults(editor.document).filter(isResultLine);
|
||||
const contextRanges = parsed.filter(line => line.isContext).map(line => line.prefixRange);
|
||||
const matchRanges = parsed.filter(line => !line.isContext).map(line => line.prefixRange);
|
||||
editor.setDecorations(contextLineDecorations, contextRanges);
|
||||
editor.setDecorations(matchLineDecorations, matchRanges);
|
||||
};
|
||||
|
||||
if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document.languageId === 'search-result') {
|
||||
decorate(vscode.window.activeTextEditor);
|
||||
}
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('searchResult.rerunSearch', () => vscode.commands.executeCommand('search.action.rerunEditorSearch')),
|
||||
vscode.commands.registerCommand('searchResult.rerunSearchWithContext', () => vscode.commands.executeCommand('search.action.rerunEditorSearchWithContext')),
|
||||
@@ -84,15 +102,24 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
}),
|
||||
|
||||
vscode.window.onDidChangeActiveTextEditor(e => {
|
||||
if (e?.document.languageId === 'search-result') {
|
||||
vscode.window.onDidChangeActiveTextEditor(editor => {
|
||||
if (editor?.document.languageId === 'search-result') {
|
||||
// Clear the parse whenever we open a new editor.
|
||||
// Conservative because things like the URI might remain constant even if the contents change, and re-parsing even large files is relatively fast.
|
||||
cachedLastParse = undefined;
|
||||
|
||||
documentChangeListener?.dispose();
|
||||
documentChangeListener = vscode.workspace.onDidChangeTextDocument(doc => {
|
||||
if (doc.document.uri === editor.document.uri) {
|
||||
decorate(editor);
|
||||
}
|
||||
});
|
||||
|
||||
decorate(editor);
|
||||
}
|
||||
}),
|
||||
|
||||
{ dispose() { cachedLastParse = undefined; } }
|
||||
{ dispose() { cachedLastParse = undefined; documentChangeListener?.dispose(); } }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,14 +156,15 @@ function relativePathToUri(path: string, resultsUri: vscode.Uri): vscode.Uri | u
|
||||
}
|
||||
|
||||
type ParsedSearchFileLine = { type: 'file', location: vscode.LocationLink, allLocations: vscode.LocationLink[], path: string };
|
||||
type ParsedSearchResultLine = { type: 'result', location: vscode.LocationLink };
|
||||
type ParsedSearchResultLine = { type: 'result', location: vscode.LocationLink, isContext: boolean, prefixRange: vscode.Range };
|
||||
type ParsedSearchResults = Array<ParsedSearchFileLine | ParsedSearchResultLine>;
|
||||
const isFileLine = (line: ParsedSearchResultLine | ParsedSearchFileLine): line is ParsedSearchFileLine => line.type === 'file';
|
||||
const isResultLine = (line: ParsedSearchResultLine | ParsedSearchFileLine): line is ParsedSearchResultLine => line.type === 'result';
|
||||
|
||||
|
||||
function parseSearchResults(document: vscode.TextDocument, token: vscode.CancellationToken): ParsedSearchResults {
|
||||
function parseSearchResults(document: vscode.TextDocument, token?: vscode.CancellationToken): ParsedSearchResults {
|
||||
|
||||
if (cachedLastParse && cachedLastParse.version === document.version) {
|
||||
if (cachedLastParse && cachedLastParse.uri === document.uri && cachedLastParse.version === document.version) {
|
||||
return cachedLastParse.parse;
|
||||
}
|
||||
|
||||
@@ -147,7 +175,8 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
|
||||
let currentTargetLocations: vscode.LocationLink[] | undefined = undefined;
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (token.isCancellationRequested) { return []; }
|
||||
// TODO: This is probably always false, given we're pegging the thread...
|
||||
if (token?.isCancellationRequested) { return []; }
|
||||
const line = lines[i];
|
||||
|
||||
const fileLine = FILE_LINE_REGEX.exec(line);
|
||||
@@ -186,13 +215,14 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
|
||||
|
||||
currentTargetLocations?.push(location);
|
||||
|
||||
links[i] = { type: 'result', location };
|
||||
links[i] = { type: 'result', location, isContext: seperator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
|
||||
}
|
||||
}
|
||||
|
||||
cachedLastParse = {
|
||||
version: document.version,
|
||||
parse: links
|
||||
parse: links,
|
||||
uri: document.uri
|
||||
};
|
||||
|
||||
return links;
|
||||
|
||||
Reference in New Issue
Block a user