Skip to content

Commit

Permalink
some editor binding
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah committed Oct 21, 2022
1 parent ac87e6a commit 704013e
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Match, FileMatch, FileMatchOrMatch } from 'vs/workbench/contrib/search/common/searchModel';
import { Match, FileMatch, FileMatchOrMatch } from 'vs/workbench/contrib/search/browser/searchModel';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { IReplaceService } from 'vs/workbench/contrib/search/browser/replace';
import { ReplaceService, ReplacePreviewContentProvider } from 'vs/workbench/contrib/search/browser/replaceService';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/search/browser/replaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import * as nls from 'vs/nls';
import { URI } from 'vs/base/common/uri';
import * as network from 'vs/base/common/network';
import { Disposable } from 'vs/base/common/lifecycle';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { IReplaceService } from 'vs/workbench/contrib/search/browser/replace';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IModelService } from 'vs/editor/common/services/model';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { Match, FileMatch, FileMatchOrMatch, ISearchWorkbenchService } from 'vs/workbench/contrib/search/common/searchModel';
import { Match, FileMatch, FileMatchOrMatch, ISearchWorkbenchService } from 'vs/workbench/contrib/search/browser/searchModel';
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
import { ITextModelService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import * as Constants from 'vs/workbench/contrib/search/common/constants';
import { resolveResourcesForSearchIncludes } from 'vs/workbench/services/search/common/queryBuilder';
import { getWorkspaceSymbols, IWorkspaceSymbol, SearchStateKey, SearchUIState } from 'vs/workbench/contrib/search/common/search';
import { ISearchHistoryService, SearchHistoryService } from 'vs/workbench/contrib/search/common/searchHistoryService';
import { FileMatch, FileMatchOrMatch, FolderMatch, FolderMatchWithResource, ISearchWorkbenchService, Match, RenderableMatch, SearchWorkbenchService } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, FileMatchOrMatch, FolderMatch, FolderMatchWithResource, ISearchWorkbenchService, Match, RenderableMatch, SearchWorkbenchService } from 'vs/workbench/contrib/search/browser/searchModel';
import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants';
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { IViewsService } from 'vs/workbench/common/views';
import { searchRemoveIcon, searchReplaceAllIcon, searchReplaceIcon } from 'vs/workbench/contrib/search/browser/searchIcons';
import { SearchView } from 'vs/workbench/contrib/search/browser/searchView';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { IReplaceService } from 'vs/workbench/contrib/search/browser/replace';
import { ISearchHistoryService } from 'vs/workbench/contrib/search/common/searchHistoryService';
import { arrayContainsElementOrParent, FileMatch, FolderMatch, FolderMatchNoRoot, FolderMatchWithResource, FolderMatchWorkspaceRoot, Match, RenderableMatch, searchComparer, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { arrayContainsElementOrParent, FileMatch, FolderMatch, FolderMatchNoRoot, FolderMatchWithResource, FolderMatchWorkspaceRoot, Match, RenderableMatch, searchComparer, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/browser/searchModel';
import { OpenEditorCommandId } from 'vs/workbench/contrib/searchEditor/browser/constants';
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
import { OpenSearchEditorArgs } from 'vs/workbench/contrib/searchEditor/browser/searchEditor.contribution';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { minimapFindMatch, overviewRulerFindMatchForeground } from 'vs/platform/theme/common/colorRegistry';
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
// import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget';
import { IReplaceService } from 'vs/workbench/contrib/search/browser/replace';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ReplacePattern } from 'vs/workbench/services/search/common/replace';
import { IFileMatch, IPatternInfo, ISearchComplete, ISearchConfigurationProperties, ISearchProgressItem, ISearchRange, ISearchService, ITextQuery, ITextSearchContext, ITextSearchMatch, ITextSearchPreviewOptions, ITextSearchResult, ITextSearchStats, OneLineRange, resultIsMatch, SearchCompletionExitCode, SearchSortOrder } from 'vs/workbench/services/search/common/search';
import { addContextToEditorMatches, editorMatchesToTextSearchResults } from 'vs/workbench/services/search/common/searchHelpers';
Expand Down Expand Up @@ -204,6 +206,7 @@ export class FileMatch extends Disposable implements IFileMatch {
private _resource: URI;
private _fileStat?: IFileStatWithPartialMetadata;
private _model: ITextModel | null = null;
private _notebookEditorWidget: NotebookEditorWidget | null = null;
private _modelListener: IDisposable | null = null;
private _matches: Map<string, Match>;
private _removedMatches: Set<string>;
Expand Down Expand Up @@ -233,7 +236,6 @@ export class FileMatch extends Disposable implements IFileMatch {
this._matches = new Map<string, Match>();
this._removedMatches = new Set<string>();
this._updateScheduler = new RunOnceScheduler(this.updateMatchesForModel.bind(this), 250);

this.createMatches();
}

Expand Down Expand Up @@ -267,6 +269,16 @@ export class FileMatch extends Disposable implements IFileMatch {
this.updateHighlights();
}

bindEditorWidget(widget: NotebookEditorWidget) {
this._notebookEditorWidget = widget;
console.log(`added widget ${this._notebookEditorWidget.textModel?.uri}`);
}

unbindEditorWidget(widget: NotebookEditorWidget) {
this._notebookEditorWidget = null;
console.log(`removed widget ${widget.textModel?.uri}`);
}

private onModelWillDispose(): void {
// Update matches because model might have some dirty changes
this.updateMatchesForModel();
Expand Down Expand Up @@ -568,6 +580,33 @@ export class FolderMatch extends Disposable {
}
}

bindEditorWidget(editor: NotebookEditorWidget, resource: URI) {
const fileMatch = this._fileMatches.get(resource);

if (fileMatch) {
fileMatch.bindEditorWidget(editor);
} else {
const folderMatches = this.folderMatchesIterator();
for (const elem of folderMatches) {
elem.bindEditorWidget(editor, resource);
}
}
}

unbindEditorWidget(editor: NotebookEditorWidget, resource: URI) {
const fileMatch = this._fileMatches.get(resource);

if (fileMatch) {
fileMatch.unbindEditorWidget(editor);
} else {
const folderMatches = this.folderMatchesIterator();
for (const elem of folderMatches) {
elem.unbindEditorWidget(editor, resource);
}
}

}

public createIntermediateFolderMatch(resource: URI, id: string, index: number, query: ITextQuery, baseWorkspaceFolder: FolderMatchWorkspaceRoot): FolderMatchWithResource {
const folderMatch = this.instantiationService.createInstance(FolderMatchWithResource, resource, id, index, query, this, this._searchModel, baseWorkspaceFolder);
this.configureIntermediateMatch(folderMatch);
Expand Down Expand Up @@ -1043,10 +1082,9 @@ export class SearchResult extends Disposable {
private _folderMatchesMap: TernarySearchTree<URI, FolderMatchWithResource> = TernarySearchTree.forUris<FolderMatchWorkspaceRoot>(key => this.uriIdentityService.extUri.ignorePathCasing(key));
private _showHighlights: boolean = false;
private _query: ITextQuery | null = null;

private _rangeHighlightDecorations: RangeHighlightDecorations;
private disposePastResults: () => void = () => { };

private _notebookEditors: Set<NotebookEditor>;
private _isDirty = false;

constructor(
Expand All @@ -1055,18 +1093,23 @@ export class SearchResult extends Disposable {
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IModelService private readonly modelService: IModelService,
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
// @IEditorService private readonly editorService: IEditorService,
@IEditorService private readonly editorService: IEditorService,
) {
super();
this._rangeHighlightDecorations = this.instantiationService.createInstance(RangeHighlightDecorations);

this._register(this.modelService.onModelAdded(model => this.onModelAdded(model)));

this._register(this.editorService.onDidVisibleEditorsChange(() => {
this.onDidVisibleEditorsChange();
}));
this._register(this.onChange(e => {
if (e.removed) {
this._isDirty = !this.isEmpty();
}
}));


this._notebookEditors = new Set<NotebookEditor>();
}

async batchReplace(elementsToReplace: RenderableMatch[]) {
Expand Down Expand Up @@ -1157,11 +1200,61 @@ export class SearchResult extends Disposable {

return retEvent;
}

private onDidVisibleEditorsChange(): void {
const visibleNotebookEditors = this.editorService.visibleEditorPanes
.map((editor) => ((editor instanceof NotebookEditor) ? (editor as NotebookEditor) : null))
.filter((editor2): editor2 is NotebookEditor => (NotebookEditor !== null));

if (visibleNotebookEditors.length === 0) {
return;
}

const oldEditors = this._notebookEditors.values();

const oldEditorsToUnbind = [];
const oldEditorsToKeepBound = [];
for (const editor of oldEditors) {
if (visibleNotebookEditors.includes(editor)) {
oldEditorsToKeepBound.push(editor);
} else {
oldEditorsToUnbind.push(editor);
}
}

for (const editor of oldEditorsToUnbind) {
const widget = editor.getControl();
// doesn't currently work because these fields are usually undefined by now on the editor
if (editor.input && editor.input.resource && widget) {
this.onNotebookEditorRemoved(widget, editor.input.resource);
this._notebookEditors.delete(editor);
}
}

for (const editor of visibleNotebookEditors) {
const widget = editor.getControl();
if (editor.input && editor.input.resource && widget) {
this.onNotebookEditorAdded(widget, editor.input.resource);
this._notebookEditors.add(editor);
}
}
}

private onModelAdded(model: ITextModel): void {
const folderMatch = this._folderMatchesMap.findSubstr(model.uri);
folderMatch?.bindModel(model);
}

private onNotebookEditorAdded(editor: NotebookEditorWidget, resource: URI): void {
const folderMatch = this._folderMatchesMap.findSubstr(resource);
folderMatch?.bindEditorWidget(editor, resource);
}

private onNotebookEditorRemoved(editor: NotebookEditorWidget, resource: URI): void {
const folderMatch = this._folderMatchesMap.findSubstr(resource);
folderMatch?.unbindEditorWidget(editor, resource);
}

private _createBaseFolderMatch(resource: URI | null, id: string, index: number, query: ITextQuery): FolderMatch {
let folderMatch;
if (resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { IResourceLabel, ResourceLabels } from 'vs/workbench/browser/labels';
import { RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { SearchView } from 'vs/workbench/contrib/search/browser/searchView';
import { FileMatch, Match, RenderableMatch, SearchModel, FolderMatch, FolderMatchNoRoot, FolderMatchWorkspaceRoot } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, Match, RenderableMatch, SearchModel, FolderMatch, FolderMatchNoRoot, FolderMatchWorkspaceRoot } from 'vs/workbench/contrib/search/browser/searchModel';
import { isEqual } from 'vs/base/common/resources';
import { ICompressibleTreeRenderer } from 'vs/base/browser/ui/tree/objectTree';
import { ICompressedTreeNode } from 'vs/base/browser/ui/tree/compressedObjectTreeModel';
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ import { renderSearchMessage } from 'vs/workbench/contrib/search/browser/searchM
import { FileMatchRenderer, FolderMatchRenderer, MatchRenderer, SearchAccessibilityProvider, SearchDelegate } from 'vs/workbench/contrib/search/browser/searchResultsView';
import { ISearchWidgetOptions, SearchWidget } from 'vs/workbench/contrib/search/browser/searchWidget';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { IReplaceService } from 'vs/workbench/contrib/search/browser/replace';
import { getOutOfWorkspaceEditorResources, SearchStateKey, SearchUIState } from 'vs/workbench/contrib/search/common/search';
import { ISearchHistoryService, ISearchHistoryValues } from 'vs/workbench/contrib/search/common/searchHistoryService';
import { FileMatch, FileMatchOrMatch, FolderMatch, FolderMatchWithResource, IChangeEvent, ISearchWorkbenchService, Match, RenderableMatch, searchMatchComparer, SearchModel, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, FileMatchOrMatch, FolderMatch, FolderMatchWithResource, IChangeEvent, ISearchWorkbenchService, Match, RenderableMatch, searchMatchComparer, SearchModel, SearchResult } from 'vs/workbench/contrib/search/browser/searchModel';
import { createEditorFromSearchResult } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
import { ACTIVE_GROUP, IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IPreferencesService, ISettingsEditorOptions } from 'vs/workbench/services/preferences/common/preferences';
Expand Down Expand Up @@ -537,6 +537,7 @@ export class SearchView extends ViewPane {
}

refreshTree(event?: IChangeEvent): void {
// animation frame and debounce
const collapseResults = this.searchConfig.collapseResults;
if (!event || event.added || event.removed) {
// Refresh whole tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { ITreeNavigator } from 'vs/base/browser/ui/tree/tree';
import { Emitter } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { RenderableMatch } from 'vs/workbench/contrib/search/common/searchModel';
import { RenderableMatch } from 'vs/workbench/contrib/search/browser/searchModel';

const someEvent = new Emitter().event;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { IFileMatch } from 'vs/workbench/services/search/common/search';
import { getElementToFocusAfterRemoved, getLastNodeFromSameType } from 'vs/workbench/contrib/search/browser/searchActions';
import { FileMatch, FileMatchOrMatch, Match } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, FileMatchOrMatch, Match } from 'vs/workbench/contrib/search/browser/searchModel';
import { MockObjectTree } from 'vs/workbench/contrib/search/test/browser/mockSearchTree';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/
import { IFileMatch, IFileSearchStats, IFolderQuery, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchService, ITextSearchMatch, OneLineRange, TextSearchMatch } from 'vs/workbench/services/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { SearchModel } from 'vs/workbench/contrib/search/common/searchModel';
import { SearchModel } from 'vs/workbench/contrib/search/browser/searchModel';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { FileService } from 'vs/platform/files/common/fileService';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { Match, FileMatch, SearchResult, SearchModel, FolderMatch } from 'vs/workbench/contrib/search/common/searchModel';
import { Match, FileMatch, SearchResult, SearchModel, FolderMatch } from 'vs/workbench/contrib/search/browser/searchModel';
import { URI } from 'vs/base/common/uri';
import { IFileMatch, TextSearchMatch, OneLineRange, ITextSearchMatch, QueryType } from 'vs/workbench/services/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
Expand All @@ -15,7 +15,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { ModelService } from 'vs/editor/common/services/modelService';
import { IModelService } from 'vs/editor/common/services/model';
import { IReplaceService } from 'vs/workbench/contrib/search/common/replace';
import { IReplaceService } from 'vs/workbench/contrib/search/browser/replace';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
import { FileMatch, FolderMatch, Match, searchComparer, searchMatchComparer, SearchModel, SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
import { FileMatch, FolderMatch, Match, searchComparer, searchMatchComparer, SearchModel, SearchResult } from 'vs/workbench/contrib/search/browser/searchModel';
import { MockLabelService } from 'vs/workbench/services/label/test/common/mockLabelService';
import { IFileMatch, ITextSearchMatch, OneLineRange, QueryType, SearchSortOrder } from 'vs/workbench/services/search/common/search';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';
Expand Down
Loading

0 comments on commit 704013e

Please sign in to comment.