Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah committed Feb 10, 2023
1 parent 2bfad50 commit 9d16b92
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/replaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ReplaceService implements IReplaceService {
if (notebookResource) {
return this.editorService.save([...this.editorService.findEditors(notebookResource)]);
} else {
return Promise.resolve();
return;
}
} else {
return this.textFileService.files.get(e.resource)?.save({ source: ReplaceService.REPLACE_SAVE_SOURCE });
Expand Down
38 changes: 20 additions & 18 deletions src/vs/workbench/contrib/search/browser/searchModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class FileMatch extends Disposable implements IFileMatch {
const experimentalNotebooksEnabled = this.configurationService.getValue<ISearchConfigurationProperties>('search').experimental.notebookSearch;
const notebookEditorWidgetBorrow = experimentalNotebooksEnabled ? this.notebookEditorService.retrieveExistingWidgetFromURI(this._resource) : undefined;
if (notebookEditorWidgetBorrow?.value) {
await this.bindEditorWidget(notebookEditorWidgetBorrow.value);
await this.bindNotebookEditorWidget(notebookEditorWidgetBorrow.value);
} else if (model) {
this.bindModel(model);
this.updateMatchesForModel();
Expand Down Expand Up @@ -357,7 +357,7 @@ export class FileMatch extends Disposable implements IFileMatch {
}
}

async bindEditorWidget(widget: NotebookEditorWidget) {
async bindNotebookEditorWidget(widget: NotebookEditorWidget) {

if (this._notebookEditorWidget === widget) {
return;
Expand All @@ -376,7 +376,7 @@ export class FileMatch extends Disposable implements IFileMatch {
await this.updateMatchesForEditorWidget();
}

unbindEditorWidget(widget?: NotebookEditorWidget) {
unbindNotebookEditorWidget(widget?: NotebookEditorWidget) {
if (widget && this._notebookEditorWidget !== widget) {
return;
}
Expand Down Expand Up @@ -608,7 +608,7 @@ export class FileMatch extends Disposable implements IFileMatch {
override dispose(): void {
this.setSelectedMatch(null);
this.unbindModel();
this.unbindEditorWidget();
this.unbindNotebookEditorWidget();
this._findMatchDecorationModel?.dispose();
this._onDispose.fire();
super.dispose();
Expand Down Expand Up @@ -740,28 +740,28 @@ export class FolderMatch extends Disposable {
}
}

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

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

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

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

Expand Down Expand Up @@ -1285,6 +1285,7 @@ export class SearchResult extends Disposable {
private _rangeHighlightDecorations: RangeHighlightDecorations;
private disposePastResults: () => void = () => { };
private _isDirty = false;
private _onWillChangeModelListener: IDisposable | undefined;

constructor(
private _searchModel: SearchModel,
Expand Down Expand Up @@ -1413,7 +1414,8 @@ export class SearchResult extends Disposable {
}

private onDidAddNotebookEditorWidget(widget: NotebookEditorWidget): void {
widget.onWillChangeModel(
this._onWillChangeModelListener?.dispose();
this._onWillChangeModelListener = widget.onWillChangeModel(
(model) => {
if (model) {
this.onNotebookEditorWidgetRemoved(widget, model?.uri);
Expand All @@ -1438,12 +1440,12 @@ export class SearchResult extends Disposable {

private async onNotebookEditorWidgetAdded(editor: NotebookEditorWidget, resource: URI): Promise<void> {
const folderMatch = this._folderMatchesMap.findSubstr(resource);
await folderMatch?.bindEditorWidget(editor, resource);
await folderMatch?.bindNotebookEditorWidget(editor, resource);
}

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

private _createBaseFolderMatch(resource: URI | null, id: string, index: number, query: ITextQuery): FolderMatch {
Expand Down Expand Up @@ -1710,7 +1712,7 @@ export class SearchModel extends Disposable {
return this._searchResult;
}

private async getLocalNotebookResults(query: ITextQuery): Promise<{ results: ResourceMap<IFileMatch | null>; limitHit: boolean }> {
private async getLocalNotebookResults(query: ITextQuery, token: CancellationToken): Promise<{ results: ResourceMap<IFileMatch | null>; limitHit: boolean }> {
const localResults = new ResourceMap<IFileMatch | null>(uri => this.uriIdentityService.extUri.getComparisonKey(uri));
let limitHit = false;

Expand All @@ -1732,7 +1734,7 @@ export class SearchModel extends Disposable {
includeMarkupPreview: false,
includeCodeInput: true,
includeOutput: false,
}, CancellationToken.None);
}, token);


if (matches.length) {
Expand All @@ -1754,8 +1756,8 @@ export class SearchModel extends Disposable {
};
}

async notebookSearch(query: ITextQuery, onProgress?: (result: ISearchProgressItem) => void): Promise<ISearchComplete> {
const localResults = await this.getLocalNotebookResults(query);
async notebookSearch(query: ITextQuery, token: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): Promise<ISearchComplete> {
const localResults = await this.getLocalNotebookResults(query, token);

if (onProgress) {
arrays.coalesce([...localResults.results.values()]).forEach(onProgress);
Expand All @@ -1778,7 +1780,7 @@ export class SearchModel extends Disposable {
};
const experimentalNotebooksEnabled = this.configurationService.getValue<ISearchConfigurationProperties>('search').experimental.notebookSearch;

const notebookResult = experimentalNotebooksEnabled ? await this.notebookSearch(query, onProgressCall) : <ISearchComplete>{ messages: [], results: [] };
const notebookResult = experimentalNotebooksEnabled ? await this.notebookSearch(query, this.currentCancelTokenSource.token, onProgressCall) : <ISearchComplete>{ messages: [], results: [] };
const currentResult = await this.searchService.textSearch(
searchQuery,
this.currentCancelTokenSource.token, onProgressCall,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ export class SearchView extends ViewPane {
if (editorWidget) {
// Ensure that the editor widget is binded. If if is, then this should return immediately.
// Otherwise, it will bind the widget.
await element.parent().bindEditorWidget(editorWidget);
await element.parent().bindNotebookEditorWidget(editorWidget);

const matchIndex = oldParentMatches.findIndex(e => e.id() === element.id());
const matches = element.parent().matches();
Expand Down

0 comments on commit 9d16b92

Please sign in to comment.