From c66787474ca09ebe6f3445fbef66f465ce12f08c Mon Sep 17 00:00:00 2001 From: Tal Amuyal Date: Wed, 25 Jul 2018 22:59:57 +0300 Subject: [PATCH] Move API out (#2459) Thanks, @Akin909 :) --- browser/src/Editor/Editor.ts | 17 ++- .../src/Editor/NeovimEditor/NeovimEditor.tsx | 6 +- browser/src/Editor/OniEditor/OniEditor.tsx | 6 +- browser/src/Plugins/Api/Oni.ts | 40 +------ browser/src/Plugins/Api/Search.ts | 32 ------ browser/src/Plugins/Api/Ui.ts | 4 +- browser/src/Services/EditorManager.ts | 26 +++++ browser/src/Services/Menu/Filter/index.ts | 13 +-- .../src/Services/Search/SearchPaneView.tsx | 5 +- browser/src/Services/Search/SearchProvider.ts | 30 ++--- browser/src/Services/Search/index.tsx | 20 ++-- .../src/Services/Snippets/SnippetSession.ts | 3 +- browser/test/Mocks/index.ts | 8 ++ .../oni-plugin-quickopen/src/QuickOpen.ts | 107 +++--------------- .../oni-plugin-quickopen/src/QuickOpenItem.ts | 5 +- package.json | 2 +- 16 files changed, 104 insertions(+), 220 deletions(-) delete mode 100644 browser/src/Plugins/Api/Search.ts diff --git a/browser/src/Editor/Editor.ts b/browser/src/Editor/Editor.ts index 5f03741a08..8ae0222bd8 100644 --- a/browser/src/Editor/Editor.ts +++ b/browser/src/Editor/Editor.ts @@ -11,18 +11,10 @@ import * as types from "vscode-languageserver-types" import { Disposable } from "./../Utility" -export interface IEditor extends Oni.Editor { - // Methods - init(filesToOpen: string[]): void - render(): JSX.Element - - setSelection(selectionRange: types.Range): Promise -} - /** * Base class for Editor implementations */ -export class Editor extends Disposable implements Oni.Editor { +export abstract class Editor extends Disposable implements Oni.Editor { private _currentMode: string private _onBufferEnterEvent = new Event() private _onBufferLeaveEvent = new Event() @@ -44,7 +36,10 @@ export class Editor extends Disposable implements Oni.Editor { return this._onCursorMoved } + public abstract init(filesToOpen: string[]): void + // Events + public get onModeChanged(): IEvent { return this._onModeChangedEvent } @@ -90,6 +85,10 @@ export class Editor extends Disposable implements Oni.Editor { return Promise.reject("Not implemented") } + public abstract render(): JSX.Element + + public abstract setSelection(selectionRange: types.Range): Promise + protected setMode(mode: Oni.Vim.Mode): void { if (mode !== this._currentMode) { this._currentMode = mode diff --git a/browser/src/Editor/NeovimEditor/NeovimEditor.tsx b/browser/src/Editor/NeovimEditor/NeovimEditor.tsx index b12f05d157..95577c1aa0 100644 --- a/browser/src/Editor/NeovimEditor/NeovimEditor.tsx +++ b/browser/src/Editor/NeovimEditor/NeovimEditor.tsx @@ -1,7 +1,7 @@ /** * NeovimEditor.ts * - * IEditor implementation for Neovim + * Editor implementation for Neovim */ import * as os from "os" @@ -66,7 +66,7 @@ import { IThemeMetadata, ThemeManager } from "./../../Services/Themes" import { TypingPredictionManager } from "./../../Services/TypingPredictionManager" import { Workspace } from "./../../Services/Workspace" -import { Editor, IEditor } from "./../Editor" +import { Editor } from "./../Editor" import { BufferManager, IBuffer } from "./../BufferManager" import { CompletionMenu } from "./CompletionMenu" @@ -99,7 +99,7 @@ import { CanvasRenderer } from "../../Renderer/CanvasRenderer" import { WebGLRenderer } from "../../Renderer/WebGL/WebGLRenderer" import { getInstance as getNotificationsInstance } from "./../../Services/Notifications" -export class NeovimEditor extends Editor implements IEditor { +export class NeovimEditor extends Editor implements Oni.Editor { private _bufferManager: BufferManager private _neovimInstance: NeovimInstance private _renderer: INeovimRenderer diff --git a/browser/src/Editor/OniEditor/OniEditor.tsx b/browser/src/Editor/OniEditor/OniEditor.tsx index dc771e1983..8e3d026a33 100644 --- a/browser/src/Editor/OniEditor/OniEditor.tsx +++ b/browser/src/Editor/OniEditor/OniEditor.tsx @@ -1,7 +1,7 @@ /** * OniEditor.ts * - * IEditor implementation for Oni + * Editor implementation for Oni * * Extends the capabilities of the NeovimEditor */ @@ -41,8 +41,6 @@ import { ThemeManager } from "./../../Services/Themes" import { TokenColors } from "./../../Services/TokenColors" import { Workspace } from "./../../Services/Workspace" -import { IEditor } from "./../Editor" - import { BufferScrollBarContainer } from "./containers/BufferScrollBarContainer" import { DefinitionContainer } from "./containers/DefinitionContainer" import { ErrorsContainer } from "./containers/ErrorsContainer" @@ -64,7 +62,7 @@ const wrapReactComponentWithLayer = (id: string, component: JSX.Element): Oni.Bu } } -export class OniEditor extends Utility.Disposable implements IEditor { +export class OniEditor extends Utility.Disposable implements Oni.Editor { private _neovimEditor: NeovimEditor public get mode(): string { diff --git a/browser/src/Plugins/Api/Oni.ts b/browser/src/Plugins/Api/Oni.ts index efbe8f971e..8f43d40583 100644 --- a/browser/src/Plugins/Api/Oni.ts +++ b/browser/src/Plugins/Api/Oni.ts @@ -27,10 +27,7 @@ import { inputManager } from "./../../Services/InputManager" import * as LanguageManager from "./../../Services/Language" import { getTutorialManagerInstance } from "./../../Services/Learning" import { getInstance as getAchievementsInstance } from "./../../Services/Learning/Achievements" -import { - getInstance as getMenuManagerInstance, - IMenuOptionWithHighlights, -} from "./../../Services/Menu" +import { getInstance as getMenuManagerInstance } from "./../../Services/Menu" import { getInstance as getFiltersInstance } from "./../../Services/Menu/Filter" import { getInstance as getNotificationsInstance } from "./../../Services/Notifications" import { getInstance as getOverlayInstance } from "./../../Services/Overlay" @@ -47,35 +44,8 @@ import { Search } from "./../../Services/Search/SearchProvider" import * as throttle from "lodash/throttle" -import { ISearch } from "./Search" // TODO: Move to oni-api - const react = require("react") // tslint:disable-line no-var-requires -// TODO: Move to oni-api -export interface QuickFixEntry { - filename: string - lnum: number - col: number - text: string -} - -// TODO: Move to oni-api under `menu` -export type IMenuFilter = (options: any[], searchString: string) => IMenuOptionWithHighlights[] - -// TODO: Move to oni-api under `menu` -export interface IMenuFilters { - getDefault(): IMenuFilter - getByName(name: string): IMenuFilter -} - -export interface ApiNext { - search: ISearch - ui: Ui - filter: IMenuFilters // TODO: Move to oni-api under menu - - populateQuickFix(entries: QuickFixEntry[]): void -} - export class Dependencies { public get React(): any { return react @@ -89,7 +59,7 @@ const helpers = { /** * API instance for interacting with OniApi (and vim) */ -export class Oni implements OniApi.Plugin.Api, ApiNext { +export class Oni implements OniApi.Plugin.Api { private _dependencies: Dependencies private _ui: Ui private _services: Services @@ -158,7 +128,7 @@ export class Oni implements OniApi.Plugin.Api, ApiNext { return getMenuManagerInstance() } - public get filter(): IMenuFilters { + public get filter(): OniApi.Menu.IMenuFilters { return getFiltersInstance("") // TODO: Pass either "core" or plugin's name } @@ -218,7 +188,7 @@ export class Oni implements OniApi.Plugin.Api, ApiNext { return helpers } - public get search(): ISearch { + public get search(): OniApi.Search.ISearch { return new Search() } @@ -228,7 +198,7 @@ export class Oni implements OniApi.Plugin.Api, ApiNext { this._services = new Services() } - public populateQuickFix(entries: QuickFixEntry[]): void { + public populateQuickFix(entries: OniApi.QuickFixEntry[]): void { const neovim: any = editorManager.activeEditor.neovim neovim.quickFix.setqflist(entries, "Search Results") neovim.command(":copen") diff --git a/browser/src/Plugins/Api/Search.ts b/browser/src/Plugins/Api/Search.ts deleted file mode 100644 index 1f4a2b61dc..0000000000 --- a/browser/src/Plugins/Api/Search.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { IEvent } from "oni-types" - -export interface ResultItem { - fileName: string - line: number - column: number - text: string -} - -export interface Result { - items: ResultItem[] - isComplete: boolean -} - -export interface Query { - onSearchResults: IEvent - - start(): void - cancel(): void -} - -export interface Options { - searchQuery: string - fileFilter: string - workspace: string -} - -export interface ISearch { - nullSearch: Query - findInFile(opts: Options): Query - findInPath(opts: Options): Query -} diff --git a/browser/src/Plugins/Api/Ui.ts b/browser/src/Plugins/Api/Ui.ts index 42f840698f..6f8b8f8683 100644 --- a/browser/src/Plugins/Api/Ui.ts +++ b/browser/src/Plugins/Api/Ui.ts @@ -1,8 +1,10 @@ +import * as Oni from "oni-api" + import { getFileIcon } from "../../Services/FileIcon" import { getInstance } from "../../Services/IconThemes" import { Icon, IconProps, IconSize } from "../../UI/Icon" -export class Ui { +export class Ui implements Oni.Ui.IUi { constructor(private _react: any) {} public createIcon(props: IconProps): any { diff --git a/browser/src/Services/EditorManager.ts b/browser/src/Services/EditorManager.ts index e2642c9ff8..721b55e260 100644 --- a/browser/src/Services/EditorManager.ts +++ b/browser/src/Services/EditorManager.ts @@ -11,6 +11,8 @@ import * as Oni from "oni-api" import { Event, IDisposable, IEvent } from "oni-types" +import * as types from "vscode-languageserver-types" + import { remote } from "electron" export class EditorManager implements Oni.EditorManager { @@ -123,6 +125,14 @@ class AnyEditorProxy implements Oni.Editor { return this._activeEditor.activeBuffer } + public init(filesToOpen: string[]): void { + if (!this._activeEditor) { + return + } + + this._activeEditor.init(filesToOpen) + } + public get neovim(): Oni.NeovimEditorCapability { if (!this._activeEditor) { return null @@ -181,6 +191,22 @@ class AnyEditorProxy implements Oni.Editor { return this._activeEditor.setTextOptions(options) } + public render(): JSX.Element { + if (!this._activeEditor) { + return null + } + + return this._activeEditor.render() + } + + public setSelection(selectionRange: types.Range): Promise { + if (!this._activeEditor) { + return null + } + + return this._activeEditor.setSelection(selectionRange) + } + /** * Internal methods */ diff --git a/browser/src/Services/Menu/Filter/index.ts b/browser/src/Services/Menu/Filter/index.ts index 7fbff4a4fb..a98a30ecde 100644 --- a/browser/src/Services/Menu/Filter/index.ts +++ b/browser/src/Services/Menu/Filter/index.ts @@ -1,13 +1,12 @@ -// import * as Oni from "oni-api" -import * as OniNext from "../../../Plugins/Api/Oni" +import * as Oni from "oni-api" import { filter as fuseFilter } from "./FuseFilter" import { filter as noFilter } from "./NoFilter" import { filter as RegExFilter } from "./RegExFilter" import { filter as vscodeFilter } from "./VSCodeFilter" -class Filters implements OniNext.IMenuFilters { - private _filters = new Map() +class Filters implements Oni.Menu.IMenuFilters { + private _filters = new Map() constructor() { this._filters @@ -18,11 +17,11 @@ class Filters implements OniNext.IMenuFilters { .set("vscode", vscodeFilter) } - public getDefault(): OniNext.IMenuFilter { + public getDefault(): Oni.Menu.IMenuFilter { return this.getByName("default") } - public getByName(name: string): OniNext.IMenuFilter { + public getByName(name: string): Oni.Menu.IMenuFilter { return this._filters.has(name) ? this._filters.get(name) : this.getDefault() } @@ -31,6 +30,6 @@ class Filters implements OniNext.IMenuFilters { const _instance = new Filters() -export function getInstance(owner: string): OniNext.IMenuFilters { +export function getInstance(owner: string): Oni.Menu.IMenuFilters { return _instance } diff --git a/browser/src/Services/Search/SearchPaneView.tsx b/browser/src/Services/Search/SearchPaneView.tsx index 47058ff209..a361a985bc 100644 --- a/browser/src/Services/Search/SearchPaneView.tsx +++ b/browser/src/Services/Search/SearchPaneView.tsx @@ -4,6 +4,7 @@ * Entry point for search-related features */ +import * as Oni from "oni-api" import * as React from "react" import { IDisposable, IEvent } from "oni-types" @@ -12,8 +13,6 @@ import { Workspace } from "./../Workspace" export * from "./SearchProvider" -import * as SearchApi from "./../../Plugins/Api/Search" // TODO: Import oni-api instead - import styled from "styled-components" import { SearchTextBox } from "./SearchTextBox" @@ -31,7 +30,7 @@ export interface ISearchPaneViewProps { onFocus: IEvent focusImmediately?: boolean - onSearchOptionsChanged: (opts: SearchApi.Options) => void + onSearchOptionsChanged: (opts: Oni.Search.Options) => void } export interface ISearchPaneViewState { diff --git a/browser/src/Services/Search/SearchProvider.ts b/browser/src/Services/Search/SearchProvider.ts index 33525918a3..981583b384 100644 --- a/browser/src/Services/Search/SearchProvider.ts +++ b/browser/src/Services/Search/SearchProvider.ts @@ -2,13 +2,13 @@ import { Event, IEvent } from "oni-types" import { configuration } from "./../Configuration" -import * as SearchApi from "./../../Plugins/Api/Search" // TODO: Import oni-api instead +import * as Oni from "oni-api" import { FinderProcess } from "./FinderProcess" import * as RipGrep from "./RipGrep" -class NullSearchQuery implements SearchApi.Query { - public _onSearchResults = new Event() +class NullSearchQuery implements Oni.Search.Query { + public _onSearchResults = new Event() public start(): void { return undefined @@ -18,17 +18,17 @@ class NullSearchQuery implements SearchApi.Query { return undefined } - public get onSearchResults(): IEvent { + public get onSearchResults(): IEvent { return this._onSearchResults } } -export class Search implements SearchApi.ISearch { - public get nullSearch(): SearchApi.Query { +export class Search implements Oni.Search.ISearch { + public get nullSearch(): Oni.Search.Query { return new NullSearchQuery() } - public findInFile(opts: SearchApi.Options): SearchApi.Query { + public findInFile(opts: Oni.Search.Options): Oni.Search.Query { const commandParts = [ RipGrep.getCommand(), "--ignore-case", @@ -42,7 +42,7 @@ export class Search implements SearchApi.ISearch { return new SearchQuery(commandParts.join(" "), parseRipGrepLine) } - public findInPath(opts: SearchApi.Options): SearchApi.Query { + public findInPath(opts: Oni.Search.Options): Oni.Search.Query { const commandParts = [ RipGrep.getCommand(), ...RipGrep.getArguments(configuration.getValue("oni.exclude")), @@ -54,7 +54,7 @@ export class Search implements SearchApi.ISearch { } } -function parseRipGrepLine(ripGrepResult: string): SearchApi.ResultItem { +function parseRipGrepLine(ripGrepResult: string): Oni.Search.ResultItem { if (!ripGrepResult || ripGrepResult.length === 0) { return null } @@ -75,7 +75,7 @@ function parseRipGrepLine(ripGrepResult: string): SearchApi.ResultItem { } } -function parseRipGrepFilesLine(line: string): SearchApi.ResultItem { +function parseRipGrepFilesLine(line: string): Oni.Search.ResultItem { if (!line || line.length === 0) { return null } @@ -88,15 +88,15 @@ function parseRipGrepFilesLine(line: string): SearchApi.ResultItem { } } -type IParseLine = (line: string) => SearchApi.ResultItem +type IParseLine = (line: string) => Oni.Search.ResultItem -class SearchQuery implements SearchApi.Query { - private _onSearchResults = new Event() +class SearchQuery implements Oni.Search.Query { + private _onSearchResults = new Event() private _finderProcess: FinderProcess - private _items: SearchApi.ResultItem[] = [] + private _items: Oni.Search.ResultItem[] = [] - public get onSearchResults(): IEvent { + public get onSearchResults(): IEvent { return this._onSearchResults } diff --git a/browser/src/Services/Search/index.tsx b/browser/src/Services/Search/index.tsx index e77faf1052..8d2857d952 100644 --- a/browser/src/Services/Search/index.tsx +++ b/browser/src/Services/Search/index.tsx @@ -1,9 +1,6 @@ import * as Oni from "oni-api" import * as Log from "oni-core-logging" -import * as OniImpl from "./../../Plugins/Api/Oni" // TODO: Import oni-api instead -import * as SearchApi from "./../../Plugins/Api/Search" // TODO: Import oni-api instead - import { Workspace } from "./../Workspace" import * as React from "react" @@ -24,9 +21,9 @@ export class SearchPane { private _onSearchCompleted = new Event() private _shouldFocusAutomatically: boolean = false - private _currentQuery: SearchApi.Query + private _currentQuery: Oni.Search.Query - private _searchOptionsObservable = new Subject() + private _searchOptionsObservable = new Subject() public get id(): string { return "oni.sidebar.search" @@ -36,11 +33,8 @@ export class SearchPane { return "Search" } - constructor( - private _onFocusEvent: IEvent, - private _oni: OniImpl.Oni, // TODO: Change to Oni.Plugin.Api - ) { - this._searchOptionsObservable.auditTime(100).subscribe((opts: SearchApi.Options) => { + constructor(private _onFocusEvent: IEvent, private _oni: Oni.Plugin.Api) { + this._searchOptionsObservable.auditTime(100).subscribe((opts: Oni.Search.Options) => { this._startNewSearch(opts) }) @@ -82,11 +76,11 @@ export class SearchPane { ) } - private _onSearchOptionsChanged(searchOpts: SearchApi.Options): void { + private _onSearchOptionsChanged(searchOpts: Oni.Search.Options): void { this._searchOptionsObservable.next(searchOpts) } - private _startNewSearch(searchOpts: SearchApi.Options): void { + private _startNewSearch(searchOpts: Oni.Search.Options): void { if (this._currentQuery) { this._currentQuery.cancel() } @@ -125,7 +119,7 @@ export function activate(oni: any): any { const searchAllFiles = () => { sidebarManager.toggleVisibilityById("oni.sidebar.search") // TODO: Use oni-api instead - // TODO: Add sidebar.setActiveEntry to the API and use oniApi instead of oni + // TODO: Add sidebar.setActiveEntry to the API and use oni as Oni (API) // oni.sidebar.setActiveEntry("oni.sidebar.search") onFocusEvent.dispatch() } diff --git a/browser/src/Services/Snippets/SnippetSession.ts b/browser/src/Services/Snippets/SnippetSession.ts index e5e84bc522..b604e4272b 100644 --- a/browser/src/Services/Snippets/SnippetSession.ts +++ b/browser/src/Services/Snippets/SnippetSession.ts @@ -14,7 +14,6 @@ import { Event, IEvent } from "oni-types" import { OniSnippet, OniSnippetPlaceholder } from "./OniSnippet" import { BufferIndentationInfo, IBuffer } from "./../../Editor/BufferManager" -import { IEditor } from "./../../Editor/Editor" import { SnippetVariableResolver } from "./SnippetVariableResolver" @@ -129,7 +128,7 @@ export class SnippetSession { return this._snippet.getLines() } - constructor(private _editor: IEditor, private _snippetString: string) {} + constructor(private _editor: Oni.Editor, private _snippetString: string) {} public async start(): Promise { this._buffer = this._editor.activeBuffer as IBuffer diff --git a/browser/test/Mocks/index.ts b/browser/test/Mocks/index.ts index 1e9d656d2e..28bec0ac71 100644 --- a/browser/test/Mocks/index.ts +++ b/browser/test/Mocks/index.ts @@ -153,6 +153,10 @@ export class MockEditor extends Editor { private _activeBuffer: MockBuffer = null private _currentSelection: types.Range = null + public init(filesToOpen: string[]): void { + throw new Error("Not implemented") + } + public get activeBuffer(): Oni.Buffer { return this._activeBuffer as any } @@ -173,6 +177,10 @@ export class MockEditor extends Editor { this.notifyBufferEnter(buffer as any) } + public render(): JSX.Element { + throw new Error("Not implemented") + } + public async setSelection(range: types.Range): Promise { this._currentSelection = range } diff --git a/extensions/oni-plugin-quickopen/src/QuickOpen.ts b/extensions/oni-plugin-quickopen/src/QuickOpen.ts index 30e7a5f2dd..b97d834a8b 100644 --- a/extensions/oni-plugin-quickopen/src/QuickOpen.ts +++ b/extensions/oni-plugin-quickopen/src/QuickOpen.ts @@ -6,74 +6,7 @@ import { Event, IEvent } from "oni-types" import { getTypeFromMenuItem, QuickOpenItem, QuickOpenType } from "./QuickOpenItem" -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -interface QuickFixEntry { - filename: string - lnum: number - col: number - text: string -} -interface IMenuOptionWithHighlights extends Oni.Menu.MenuOption { - labelHighlights: number[] - detailHighlights: number[] -} -type IMenuFilter = (options: any[], searchString: string) => IMenuOptionWithHighlights[] -interface IMenuFilters { - getDefault(): IMenuFilter - getByName(name: string): IMenuFilter -} -namespace SearchApi { - export interface ResultItem { - fileName: string - line: number - column: number - text: string - } - export interface Result { - items: ResultItem[] - isComplete: boolean - } - export interface Query { - onSearchResults: IEvent - start(): void - cancel(): void - } - export interface Options { - searchQuery: string - fileFilter: string - workspace: string - } - export interface ISearch { - nullSearch: Query - findInFile(opts: Options): Query - findInPath(opts: Options): Query - } -} -interface ApiNext { - search: SearchApi.ISearch - populateQuickFix(entries: QuickFixEntry[]): void - - // TODO: Move to oni-api under menu - filter: IMenuFilters -} -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ -/* !!! DELETE !!! */ - -type CreateQuery = (text: string) => SearchApi.Query +type CreateQuery = (text: string) => Oni.Search.Query interface QuickOpenResult { items: QuickOpenItem[] @@ -170,11 +103,11 @@ class BufferLinesSearch implements IAsyncSearch { } class FilePathSearch implements IAsyncSearch { - private _activeQuery: SearchApi.Query + private _activeQuery: Oni.Search.Query private _onSearchResults = new Event() private _cached = false - constructor(private _oni: Oni.Plugin.Api, private _oniNext: ApiNext) {} + constructor(private _oni: Oni.Plugin.Api) {} public cancel(): void {} @@ -184,7 +117,7 @@ class FilePathSearch implements IAsyncSearch { } this._cached = true - const activeQuery = this._oniNext.search.findInPath({ + const activeQuery = this._oni.search.findInPath({ searchQuery: null, fileFilter: null, workspace: null, @@ -203,7 +136,7 @@ class FilePathSearch implements IAsyncSearch { return this._onSearchResults } - private static toQuickOpenItem(i: SearchApi.ResultItem): QuickOpenItem { + private static toQuickOpenItem(i: Oni.Search.ResultItem): QuickOpenItem { return new QuickOpenItem( path.basename(i.fileName), path.dirname(i.fileName), @@ -216,16 +149,16 @@ class FilePathSearch implements IAsyncSearch { } class FileContentSearch implements IAsyncSearch { - private _activeQuery: SearchApi.Query + private _activeQuery: Oni.Search.Query private _onSearchResults = new Event() - constructor(private _oni: Oni.Plugin.Api, private _oniNext: ApiNext) { - this._activeQuery = this._oniNext.search.nullSearch + constructor(private _oni: Oni.Plugin.Api) { + this._activeQuery = this._oni.search.nullSearch } public cancel(): void { this._activeQuery.cancel() - this._activeQuery = this._oniNext.search.nullSearch + this._activeQuery = this._oni.search.nullSearch } public changeQueryText(newText): void { @@ -244,7 +177,7 @@ class FileContentSearch implements IAsyncSearch { fileFilter: null, workspace: null, } - this._activeQuery = this._oniNext.search.findInFile(searchParams) + this._activeQuery = this._oni.search.findInFile(searchParams) this._activeQuery.onSearchResults.subscribe(result => { this._onSearchResults.dispatch({ items: result.items.map(i => FileContentSearch.toQuickOpenItem(i)), @@ -258,7 +191,7 @@ class FileContentSearch implements IAsyncSearch { return this._onSearchResults } - private static toQuickOpenItem(i: SearchApi.ResultItem): QuickOpenItem { + private static toQuickOpenItem(i: Oni.Search.ResultItem): QuickOpenItem { return new QuickOpenItem( i.text, path.basename(i.fileName), @@ -277,14 +210,10 @@ function getHome(): string { export class QuickOpen { private _menu: Oni.Menu.MenuInstance private _searcher: IAsyncSearch = new NullSearch() - private _oniNext: ApiNext // TODO: Remove private _seenItems: Set = new Set() private _itemsFound: QuickOpenItem[] = [] constructor(private _oni: Oni.Plugin.Api) { - const typelessOni: any = _oni - this._oniNext = typelessOni - this._menu = _oni.menu.create() this._menu.onHide.subscribe(() => { @@ -387,7 +316,7 @@ export class QuickOpen { } public async setToQuickFix() { - this._oniNext.populateQuickFix(this._itemsFound.map(item => item.toQuickFixItem())) + this._oni.populateQuickFix(this._itemsFound.map(item => item.toQuickFixItem())) this._menu.hide() } @@ -400,10 +329,7 @@ export class QuickOpen { public async searchFileByContent() { const filterName = "none" // TODO: Use a filter like `regex` (needs a few adjustments) - const searcher = new FileContentSearch( - this._oni, - this._oniNext, // TODO: Remove - ) + const searcher = new FileContentSearch(this._oni) await this.search(searcher, filterName) } @@ -414,10 +340,7 @@ export class QuickOpen { ) const searchEngine = this.isInstallDirectoryOrHome() ? new BookmarkSearch(this._oni) - : new FilePathSearch( - this._oni, - this._oniNext, // TODO: Remove - ) + : new FilePathSearch(this._oni) await this.search(searchEngine, filterName) } @@ -428,7 +351,7 @@ export class QuickOpen { private async search(searcher: IAsyncSearch, filterName: string) { this._searcher.cancel() - const filterFunction = this._oniNext.filter.getByName(filterName) + const filterFunction = this._oni.filter.getByName(filterName) this._menu.setFilterFunction(filterFunction) this._searcher = searcher searcher.onSearchResults.subscribe((result: QuickOpenResult) => { diff --git a/extensions/oni-plugin-quickopen/src/QuickOpenItem.ts b/extensions/oni-plugin-quickopen/src/QuickOpenItem.ts index 07449e3261..f18a484378 100644 --- a/extensions/oni-plugin-quickopen/src/QuickOpenItem.ts +++ b/extensions/oni-plugin-quickopen/src/QuickOpenItem.ts @@ -47,8 +47,7 @@ export class QuickOpenItem { } } - // TODO: Uncomment ret val, requires exposing in oni-api - public toQuickFixItem() /*: Oni.QuickFixEntry*/ { + public toQuickFixItem(): Oni.QuickFixEntry { return { filename: this._path, lnum: this._line, @@ -76,7 +75,7 @@ export class QuickOpenItem { case QuickOpenType.bookmarkHelp: return "info" case QuickOpenType.file: - return (oni as any).ui.getFileIcon(this._label) + return oni.ui.getFileIcon(this._label) case QuickOpenType.folder: return "folder-o" case QuickOpenType.folderHelp: diff --git a/package.json b/package.json index 9497c855cb..a6a8c9f55a 100644 --- a/package.json +++ b/package.json @@ -705,7 +705,7 @@ "minimist": "1.2.0", "msgpack-lite": "0.1.26", "ocaml-language-server": "^1.0.27", - "oni-api": "^0.0.46", + "oni-api": "0.0.48", "oni-neovim-binaries": "0.1.2", "oni-ripgrep": "0.0.4", "oni-types": "^0.0.8",