提交 9ea81df9 编写于 作者: J Jackson Kearl

Working directory in state that gives ts build error

上级 4fe7d7d1
......@@ -17,3 +17,27 @@ export const EnableSearchEditorPreview = new RawContextKey<boolean>('previewSear
export const InSearchEditor = new RawContextKey<boolean>('inSearchEditor', false);
export const SearchEditorScheme = 'search-editor';
export type SearchConfiguration = {
query: string,
includes: string,
excludes: string
contextLines: number,
wholeWord: boolean,
caseSensitive: boolean,
regexp: boolean,
useIgnores: boolean,
showIncludesExcludes: boolean,
};
export const DEFAULT_SEARCH_CONFIG: Readonly<SearchConfiguration> = {
query: '',
includes: '',
excludes: '',
contextLines: 0,
wholeWord: false,
caseSensitive: false,
regexp: false,
useIgnores: true,
showIncludesExcludes: false,
};
......@@ -38,11 +38,11 @@ import { serializeSearchResultForEditor } from 'vs/workbench/contrib/searchEdito
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { InputBoxFocusedKey } from 'vs/workbench/contrib/search/common/constants';
import { IEditorProgressService, LongRunningOperation } from 'vs/platform/progress/common/progress';
import type { SearchEditorInput, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import type { SearchEditorInput } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import { searchEditorFindMatchBorder, searchEditorFindMatch, registerColor, inputBorder } from 'vs/platform/theme/common/colorRegistry';
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { ReferencesController } from 'vs/editor/contrib/gotoSymbol/peek/referencesController';
import { InSearchEditor } from 'vs/workbench/contrib/searchEditor/browser/constants';
import { InSearchEditor, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/constants';
const RESULT_LINE_REGEX = /^(\s+)(\d+)(:| )(\s+)(.*)$/;
const FILE_LINE_REGEX = /^(\S.*):$/;
......@@ -334,7 +334,7 @@ export class SearchEditor extends BaseEditor {
controller.closeWidget(false);
const labelFormatter = (uri: URI): string => this.labelService.getUriLabel(uri, { relative: true });
const results = serializeSearchResultForEditor(searchModel.searchResult, config.includes, config.excludes, config.contextLines, labelFormatter, true);
const results = serializeSearchResultForEditor(searchModel.searchResult, config.includes, config.excludes, config.contextLines, labelFormatter, false);
const textModel = assertIsDefined(this.searchResultEditor.getModel());
this.modelService.updateModel(textModel, results.text);
this.getInput()?.setDirty(this.getInput()?.resource.scheme !== 'search-editor');
......@@ -377,7 +377,7 @@ export class SearchEditor extends BaseEditor {
await super.setInput(newInput, options, token);
this.inSearchEditorContextKey.set(true);
const { model, query } = await newInput.reloadModel();
const { resultsTextModel: model, searchConfig: query } = await newInput.reloadModel();
this.searchResultEditor.setModel(model);
this.pauseSearching = true;
......
......@@ -10,14 +10,15 @@ import { isEqual, joinPath, toLocalResource } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import 'vs/css!./media/searchEditor';
import type { ICodeEditorViewState } from 'vs/editor/common/editorCommon';
import { IModelDeltaDecoration, ITextBufferFactory, ITextModel } from 'vs/editor/common/model';
import { IModelDeltaDecoration, ITextBufferFactory } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { localize } from 'vs/nls';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { EditorInput, GroupIdentifier, IEditorInput, IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
import { SearchEditorScheme, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/constants';
import { SearchEditorModel } from 'vs/workbench/contrib/searchEditor/browser/searchEditorModel';
import { extractSearchQuery, serializeSearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
......@@ -26,19 +27,6 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import { AutoSaveMode, IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { ITextFileSaveOptions, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IWorkingCopy, IWorkingCopyBackup, IWorkingCopyService, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { SearchEditorScheme } from 'vs/workbench/contrib/searchEditor/browser/constants';
export type SearchConfiguration = {
query: string,
includes: string,
excludes: string
contextLines: number,
wholeWord: boolean,
caseSensitive: boolean,
regexp: boolean,
useIgnores: boolean,
showIncludesExcludes: boolean,
};
type SearchEditorViewState =
| { focused: 'input' }
......@@ -48,7 +36,7 @@ export class SearchEditorInput extends EditorInput {
static readonly ID: string = 'workbench.editorinputs.searchEditorInput';
private dirty: boolean = false;
private readonly model: Promise<ITextModel>;
private readonly model: Promise<SearchEditorModel>;
private query: Partial<SearchConfiguration> | undefined;
private readonly _onDidChangeContent = new Emitter<void>();
......@@ -60,7 +48,7 @@ export class SearchEditorInput extends EditorInput {
constructor(
public readonly resource: URI,
getModel: () => Promise<ITextModel>,
getModel: () => Promise<SearchEditorModel>,
startingConfig: Partial<SearchConfiguration> | undefined,
@IModelService private readonly modelService: IModelService,
@IEditorService protected readonly editorService: IEditorService,
......@@ -77,7 +65,8 @@ export class SearchEditorInput extends EditorInput {
this.model = getModel()
.then(model => {
this._register(model.onDidChangeContent(() => this._onDidChangeContent.fire()));
this._register(model.resultsTextModel.onDidChangeContent(() => this._onDidChangeContent.fire()));
this._register(model);
return model;
});
......@@ -109,7 +98,7 @@ export class SearchEditorInput extends EditorInput {
if (this.isUntitled()) {
return this.saveAs(group, options);
} else {
await this.textFileService.write(this.resource, (await this.model).getValue(), options);
await this.textFileService.write(this.resource, (await this.model).createSnapshot(), options);
this.setDirty(false);
return this;
}
......@@ -122,7 +111,7 @@ export class SearchEditorInput extends EditorInput {
if (await this.textFileService.saveAs(this.resource, path, options)) {
this.setDirty(false);
if (!isEqual(path, this.resource)) {
const input = this.instantiationService.invokeFunction(getOrMakeSearchEditorInput, { uri: path });
const input = this.instantiationService.invokeFunction(getOrMakeSearchEditorInput, { uri: path, config: { ...this.query } });
input.setHighlights(this.highlights);
return input;
}
......@@ -152,12 +141,15 @@ export class SearchEditorInput extends EditorInput {
async reloadModel() {
const model = await this.model;
const query = extractSearchQuery(model);
this.query = query;
this._highlights = model.getAllDecorations();
this.query = model.searchConfig;
this._highlights = model.resultsTextModel.getAllDecorations();
this._onDidChangeLabel.fire();
return { model, query };
return model;
}
async setConfig(config: Partial<SearchConfiguration>) {
(await this.model).setConfig(config);
}
getConfigSync() {
......@@ -232,7 +224,7 @@ export class SearchEditorInput extends EditorInput {
public async setHighlights(value: IModelDeltaDecoration[]) {
if (!value) { return; }
const model = await this.model;
model.deltaDecorations([], value);
model.resultsTextModel.deltaDecorations([], value);
this._highlights = value;
}
......@@ -251,7 +243,7 @@ export class SearchEditorInput extends EditorInput {
// Bringing this over from textFileService because it only suggests for untitled scheme.
// In the future I may just use the untitled scheme. I dont get particular benefit from using search-editor...
private async suggestFileName(): Promise<URI> {
const query = (await this.reloadModel()).query.query;
const query = (await this.reloadModel()).searchConfig.query;
const searchFileName = (query.replace(/[^\w \-_]+/g, '_') || 'Search') + '.code-search';
......@@ -282,7 +274,6 @@ export const getOrMakeSearchEditorInput = (
const modelService = accessor.get(IModelService);
const textFileService = accessor.get(ITextFileService);
const backupService = accessor.get(IBackupFileService);
const modeService = accessor.get(IModeService);
const existing = inputs.get(uri.toString());
if (existing) {
......@@ -292,8 +283,11 @@ export const getOrMakeSearchEditorInput = (
const config = existingData.config ?? (existingData.text ? extractSearchQuery(existingData.text) : {});
const getModel = async () => {
const existing = modelService.getModel(uri);
if (existing) { return existing; }
if (existing) {
return instantiationService.createInstance(SearchEditorModel, { resultsTextModel: existing, searchConfig: config }, uri);
}
const backup = await backupService.resolve(uri);
backupService.discardBackup(uri);
......@@ -312,7 +306,7 @@ export const getOrMakeSearchEditorInput = (
throw new Error('no initial contents for search editor');
}
return modelService.createModel(contents, modeService.create('search-result'), uri);
return instantiationService.createInstance(SearchEditorModel, { rawTextModel: contents }, uri);
};
const input = instantiationService.createInstance(SearchEditorInput, uri, getModel, config);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ITextModel, ITextBufferFactory, DefaultEndOfLine, ITextSnapshot } from 'vs/editor/common/model';
import { SearchConfiguration, DEFAULT_SEARCH_CONFIG } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import { createTextBuffer } from 'vs/editor/common/model/textModel';
import { IModelService } from 'vs/editor/common/services/modelService';
import { extractSearchQuery, serializeSearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
import { IModeService } from 'vs/editor/common/services/modeService';
import { URI } from 'vs/base/common/uri';
import { Disposable } from 'vs/base/common/lifecycle';
import { stringToSnapshot } from 'vs/workbench/services/textfile/common/textfiles';
import { Event, Emitter } from 'vs/base/common/event';
type SearchEditorModelConfig =
| { rawTextModel: string | ITextBufferFactory, resultsTextModel?: never, searchConfig?: never }
| { resultsTextModel: ITextModel, searchConfig: Partial<SearchConfiguration>, rawTextModel?: never }
;
export class SearchEditorModel extends Disposable {
public resultsTextModel: ITextModel;
public searchConfig!: SearchConfiguration;
private readonly _onDispose = new Emitter<void>();
readonly onDispose: Event<void> = this._onDispose.event;
constructor(config: SearchEditorModelConfig, uri: URI,
@IModelService private readonly modelService: IModelService,
@IModeService private readonly modeService: IModeService,
) {
super();
if (config.rawTextModel !== undefined) {
const buffer = createTextBuffer(config.rawTextModel, DefaultEndOfLine.LF);
const header = [];
const body = [];
let inHeader = true;
for (const line of buffer.getLinesContent()) {
if (inHeader) {
if (line.startsWith('#')) {
header.push(line);
} else if (line === '') {
inHeader = false;
}
} else {
body.push(line);
}
}
this.searchConfig = extractSearchQuery(header.join('\n'));
this.resultsTextModel = this.modelService.createModel(
body.join('\n'),
this.modeService.create('search-result'),
uri);
} else {
this.resultsTextModel = config.resultsTextModel;
this.setConfig(config.searchConfig);
}
this._register(this.resultsTextModel);
}
setConfig(config: Partial<SearchConfiguration>) {
this.searchConfig = { ...DEFAULT_SEARCH_CONFIG, ...config };
}
createSnapshot(): ITextSnapshot {
return stringToSnapshot(serializeSearchConfiguration(this.searchConfig) + this.resultsTextModel.getValue());
}
isDisposed() {
return this.resultsTextModel.isDisposed();
}
async load() {
return this.resultsTextModel;
}
}
......@@ -12,7 +12,7 @@ import { FileMatch, Match, searchMatchComparer, SearchResult } from 'vs/workbenc
import { ITextQuery } from 'vs/workbench/services/search/common/search';
import { localize } from 'vs/nls';
import type { ITextModel } from 'vs/editor/common/model';
import type { SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import { SearchConfiguration, DEFAULT_SEARCH_CONFIG } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
// Using \r\n on Windows inserts an extra newline between results.
const lineDelimiter = '\n';
......@@ -146,17 +146,7 @@ export const extractSearchQuery = (model: ITextModel | string): SearchConfigurat
? model
: model.getValueInRange(new Range(1, 1, 6, 1)).split(lineDelimiter);
const query: SearchConfiguration = {
query: '',
includes: '',
excludes: '',
regexp: false,
caseSensitive: false,
useIgnores: true,
wholeWord: false,
contextLines: 0,
showIncludesExcludes: false,
};
const query: SearchConfiguration = { ...DEFAULT_SEARCH_CONFIG };
const unescapeNewlines = (str: string) => {
let out = '';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册