提交 8c0fdc2b 编写于 作者: U Ubuntu

Fix #69687 - strict null check search

上级 30b2c307
......@@ -36,6 +36,7 @@
"./vs/workbench/contrib/webview/**/*.ts",
"./vs/workbench/contrib/preferences/common/**/*.ts",
"./vs/workbench/contrib/preferences/**/settings*.ts",
"./vs/workbench/contrib/search/**/*.ts",
"./vs/workbench/contrib/terminal/**/*"
],
"files": [
......
......@@ -365,15 +365,15 @@ const searchInFolderCommand: ICommandHandler = (accessor, resource?: URI) => {
const panelService = accessor.get(IPanelService);
const fileService = accessor.get(IFileService);
const configurationService = accessor.get(IConfigurationService);
const resources = getMultiSelectedResources(resource, listService, accessor.get(IEditorService));
const resources = resource && getMultiSelectedResources(resource, listService, accessor.get(IEditorService));
return openSearchView(viewletService, panelService, configurationService, true).then(searchView => {
if (resources && resources.length) {
if (resources && resources.length && searchView) {
return fileService.resolveFiles(resources.map(resource => ({ resource }))).then(results => {
const folders: URI[] = [];
results.forEach(result => {
if (result.success) {
if (result.success && result.stat) {
folders.push(result.stat.isDirectory ? result.stat.resource : dirname(result.stat.resource));
}
});
......@@ -414,7 +414,9 @@ CommandsRegistry.registerCommand({
id: FIND_IN_WORKSPACE_ID,
handler: (accessor) => {
return openSearchView(accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(IConfigurationService), true).then(searchView => {
searchView.searchInFolders(null);
if (searchView) {
searchView.searchInFolders();
}
});
}
});
......@@ -456,7 +458,7 @@ class ShowAllSymbolsAction extends Action {
run(context?: any): Promise<void> {
let prefix = ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX;
let inputSelection: { start: number; end: number; } = undefined;
let inputSelection: { start: number; end: number; } | undefined = undefined;
const editor = this.editorService.getFocusedCodeEditor();
const word = editor && getSelectionSearchString(editor);
if (word) {
......
......@@ -52,14 +52,15 @@ export function appendKeyBindingLabel(label: string, inputKeyBinding: number | R
}
}
export function openSearchView(viewletService: IViewletService, panelService: IPanelService, configurationService: IConfigurationService, focus?: boolean): Promise<SearchView> {
export function openSearchView(viewletService: IViewletService, panelService: IPanelService, configurationService: IConfigurationService, focus?: boolean): Promise<SearchView | undefined> {
if (configurationService.getValue<ISearchConfiguration>().search.location === 'panel') {
return Promise.resolve((panelService.openPanel(PANEL_ID, focus) as SearchPanel).getSearchView());
}
return viewletService.openViewlet(VIEWLET_ID, focus).then(viewlet => (viewlet as SearchViewlet).getSearchView());
}
export function getSearchView(viewletService: IViewletService, panelService: IPanelService): SearchView | null {
export function getSearchView(viewletService: IViewletService, panelService: IPanelService): SearchView | undefined {
const activeViewlet = viewletService.getActiveViewlet();
if (activeViewlet && activeViewlet.getId() === VIEWLET_ID) {
return (activeViewlet as SearchViewlet).getSearchView();
......@@ -70,7 +71,7 @@ export function getSearchView(viewletService: IViewletService, panelService: IPa
return (activePanel as SearchPanel).getSearchView();
}
return null;
return undefined;
}
function doAppendKeyBindingLabel(label: string, keyBinding: ResolvedKeybinding | undefined): string {
......@@ -149,11 +150,13 @@ export abstract class FindOrReplaceInFilesAction extends Action {
run(): Promise<any> {
return openSearchView(this.viewletService, this.panelService, this.configurationService, false).then(openedView => {
const searchAndReplaceWidget = openedView.searchAndReplaceWidget;
searchAndReplaceWidget.toggleReplace(this.expandSearchReplaceWidget);
if (openedView) {
const searchAndReplaceWidget = openedView.searchAndReplaceWidget;
searchAndReplaceWidget.toggleReplace(this.expandSearchReplaceWidget);
const updatedText = openedView.updateTextFromSelection(!this.expandSearchReplaceWidget);
openedView.searchAndReplaceWidget.focus(undefined, updatedText, updatedText);
const updatedText = openedView.updateTextFromSelection(!this.expandSearchReplaceWidget);
openedView.searchAndReplaceWidget.focus(undefined, updatedText, updatedText);
}
});
}
}
......@@ -240,7 +243,7 @@ export class RefreshAction extends Action {
static readonly ID: string = 'search.action.refreshSearchResults';
static LABEL: string = nls.localize('RefreshAction.label', "Refresh");
private searchView: SearchView | null;
private searchView: SearchView | undefined;
constructor(id: string, label: string,
@IViewletService private readonly viewletService: IViewletService,
......@@ -394,7 +397,9 @@ export class FocusNextSearchResultAction extends Action {
run(): Promise<any> {
return openSearchView(this.viewletService, this.panelService, this.configurationService).then(searchView => {
searchView.selectNextMatch();
if (searchView) {
searchView.selectNextMatch();
}
});
}
}
......@@ -413,7 +418,9 @@ export class FocusPreviousSearchResultAction extends Action {
run(): Promise<any> {
return openSearchView(this.viewletService, this.panelService, this.configurationService).then(searchView => {
searchView.selectPreviousMatch();
if (searchView) {
searchView.selectPreviousMatch();
}
});
}
}
......@@ -771,6 +778,8 @@ export const focusSearchListCommand: ICommandHandler = accessor => {
const panelService = accessor.get(IPanelService);
const configurationService = accessor.get(IConfigurationService);
openSearchView(viewletService, panelService, configurationService).then(searchView => {
searchView.moveFocusToResults();
if (searchView) {
searchView.moveFocusToResults();
}
});
};
......@@ -64,7 +64,7 @@ export class SearchPanel extends Panel {
super.saveState();
}
getSearchView(): SearchView | null {
getSearchView(): SearchView {
return this.searchView;
}
}
\ No newline at end of file
......@@ -115,13 +115,13 @@ export class SearchView extends ViewletPanel {
private inputPatternIncludes: PatternInputWidget;
private resultsElement: HTMLElement;
private currentSelectedFileMatch: FileMatch;
private currentSelectedFileMatch: FileMatch | undefined;
private readonly selectCurrentMatchEmitter: Emitter<string | undefined>;
private delayedRefresh: Delayer<void>;
private changedWhileHidden: boolean;
private searchWithoutFolderMessageElement: HTMLElement;
private searchWithoutFolderMessageElement: HTMLElement | undefined;
private currentSearchQ = Promise.resolve();
......@@ -474,7 +474,7 @@ export class SearchView extends ViewletPanel {
});
}
private createFolderIterator(folderMatch: FolderMatch, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterator<ITreeElement<RenderableMatch>> {
private createFolderIterator(folderMatch: BaseFolderMatch, collapseResults: ISearchConfigurationProperties['collapseResults']): Iterator<ITreeElement<RenderableMatch>> {
const filesIt = Iterator.fromArray(
folderMatch.matches()
.sort(searchMatchComparer));
......@@ -797,7 +797,7 @@ export class SearchView extends ViewletPanel {
updateTextFromSelection(allowUnselectedWord = true): boolean {
let updatedText = false;
const seedSearchStringFromSelection = this.configurationService.getValue<IEditorOptions>('editor').find.seedSearchStringFromSelection;
const seedSearchStringFromSelection = this.configurationService.getValue<IEditorOptions>('editor').find!.seedSearchStringFromSelection;
if (seedSearchStringFromSelection) {
let selectedText = this.getSearchTextFromEditor(allowUnselectedWord);
if (selectedText) {
......@@ -1074,7 +1074,7 @@ export class SearchView extends ViewletPanel {
}
}
searchInFolders(resources: URI[]): void {
searchInFolders(resources?: URI[]): void {
const folderPaths: string[] = [];
const workspace = this.contextService.getWorkspace();
......@@ -1338,7 +1338,7 @@ export class SearchView extends ViewletPanel {
const onError = (e: any) => {
if (errors.isPromiseCanceledError(e)) {
return onComplete(null);
return onComplete(undefined);
} else {
this.searching = false;
this.updateActions();
......@@ -1422,7 +1422,7 @@ export class SearchView extends ViewletPanel {
this.openSettings('.exclude');
}
private openSettings(query: string): Promise<IEditor> {
private openSettings(query: string): Promise<IEditor | null> {
const options: ISettingsEditorOptions = { query };
return this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY ?
this.preferencesService.openWorkspaceSettings(undefined, options) :
......@@ -1480,7 +1480,7 @@ export class SearchView extends ViewletPanel {
const actionClass = env.isMacintosh ? OpenFileFolderAction : OpenFolderAction;
const action = this.instantiationService.createInstance<string, string, IAction>(actionClass, actionClass.ID, actionClass.LABEL);
this.actionRunner.run(action).then(() => {
this.actionRunner!.run(action).then(() => {
action.dispose();
}, err => {
action.dispose();
......@@ -1499,7 +1499,7 @@ export class SearchView extends ViewletPanel {
// this.replaceService.disposeAllReplacePreviews();
dom.hide(this.messagesElement);
dom.show(this.resultsElement);
this.currentSelectedFileMatch = null;
this.currentSelectedFileMatch = undefined;
}
private onFocus(lineMatch: any, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<any> {
......@@ -1514,7 +1514,7 @@ export class SearchView extends ViewletPanel {
this.open(lineMatch, preserveFocus, sideBySide, pinned);
}
open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<any> {
open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Promise<void> {
const selection = this.getSelectionFrom(element);
const resource = element instanceof Match ? element.parent().resource() : (<FileMatch>element).resource();
return this.editorService.openEditor({
......@@ -1528,7 +1528,7 @@ export class SearchView extends ViewletPanel {
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => {
if (editor && element instanceof Match && preserveFocus) {
this.viewModel.searchResult.rangeHighlightDecorations.highlightRange(
(<ICodeEditor>editor.getControl()).getModel(),
(<ICodeEditor>editor.getControl()).getModel()!,
element.range()
);
} else {
......@@ -1536,9 +1536,7 @@ export class SearchView extends ViewletPanel {
}
if (editor) {
return this.editorGroupsService.activateGroup(editor.group);
} else {
return Promise.resolve(null);
this.editorGroupsService.activateGroup(editor.group!);
}
}, errors.onUnexpectedError);
}
......
......@@ -38,8 +38,8 @@ export class SearchViewlet extends ViewContainerViewlet {
return Registry.as<ViewletRegistry>(Extensions.Viewlets).getViewlet(this.getId()).name;
}
getSearchView(): SearchView | null {
getSearchView(): SearchView | undefined {
const view = super.getView(VIEW_ID);
return view ? view as SearchView : null;
return view ? view as SearchView : undefined;
}
}
\ No newline at end of file
......@@ -56,7 +56,7 @@ class ReplaceAllAction extends Action {
return ReplaceAllAction.fgInstance;
}
private _searchWidget: SearchWidget | null = null;
private _searchWidget: SearchWidget;
constructor() {
super(ReplaceAllAction.ID, '', 'action-replace-all', false);
......@@ -113,8 +113,8 @@ export class SearchWidget extends Widget {
private _onReplaceStateChange = this._register(new Emitter<boolean>());
readonly onReplaceStateChange: Event<boolean> = this._onReplaceStateChange.event;
private _onReplaceValueChanged = this._register(new Emitter<string | undefined>());
readonly onReplaceValueChanged: Event<string> = this._onReplaceValueChanged.event;
private _onReplaceValueChanged = this._register(new Emitter<void>());
readonly onReplaceValueChanged: Event<void> = this._onReplaceValueChanged.event;
private _onReplaceAll = this._register(new Emitter<void>());
readonly onReplaceAll: Event<void> = this._onReplaceAll.event;
......@@ -343,7 +343,7 @@ export class SearchWidget extends Widget {
this._register(attachInputBoxStyler(this.replaceInput, this.themeService));
this.onkeydown(this.replaceInput.inputElement, (keyboardEvent) => this.onReplaceInputKeyDown(keyboardEvent));
this.replaceInput.value = options.replaceValue || '';
this._register(this.replaceInput.onDidChange(() => this._onReplaceValueChanged.fire(undefined)));
this._register(this.replaceInput.onDidChange(() => this._onReplaceValueChanged.fire()));
this._register(this.replaceInput.onDidHeightChange(() => this._onDidHeightChange.fire()));
this.replaceAllAction = ReplaceAllAction.INSTANCE;
......@@ -532,8 +532,6 @@ export class SearchWidget extends Widget {
dispose(): void {
this.setReplaceAllActionState(false);
this.replaceAllAction.searchWidget = null;
this.replaceActionBar = null;
super.dispose();
}
......
......@@ -389,7 +389,7 @@ export class FileMatch extends Disposable {
}
export interface IChangeEvent {
elements: (FileMatch | FolderMatch | SearchResult | null)[];
elements: (FileMatch | FolderMatch | SearchResult)[];
added?: boolean;
removed?: boolean;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册