Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Commit c667874

Browse files
authored
Move API out (#2459)
Thanks, @akin909 :)
1 parent ecbd4af commit c667874

File tree

16 files changed

+104
-220
lines changed

16 files changed

+104
-220
lines changed

browser/src/Editor/Editor.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ import * as types from "vscode-languageserver-types"
1111

1212
import { Disposable } from "./../Utility"
1313

14-
export interface IEditor extends Oni.Editor {
15-
// Methods
16-
init(filesToOpen: string[]): void
17-
render(): JSX.Element
18-
19-
setSelection(selectionRange: types.Range): Promise<void>
20-
}
21-
2214
/**
2315
* Base class for Editor implementations
2416
*/
25-
export class Editor extends Disposable implements Oni.Editor {
17+
export abstract class Editor extends Disposable implements Oni.Editor {
2618
private _currentMode: string
2719
private _onBufferEnterEvent = new Event<Oni.EditorBufferEventArgs>()
2820
private _onBufferLeaveEvent = new Event<Oni.EditorBufferEventArgs>()
@@ -44,7 +36,10 @@ export class Editor extends Disposable implements Oni.Editor {
4436
return this._onCursorMoved
4537
}
4638

39+
public abstract init(filesToOpen: string[]): void
40+
4741
// Events
42+
4843
public get onModeChanged(): IEvent<Oni.Vim.Mode> {
4944
return this._onModeChangedEvent
5045
}
@@ -90,6 +85,10 @@ export class Editor extends Disposable implements Oni.Editor {
9085
return Promise.reject("Not implemented")
9186
}
9287

88+
public abstract render(): JSX.Element
89+
90+
public abstract setSelection(selectionRange: types.Range): Promise<void>
91+
9392
protected setMode(mode: Oni.Vim.Mode): void {
9493
if (mode !== this._currentMode) {
9594
this._currentMode = mode

browser/src/Editor/NeovimEditor/NeovimEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* NeovimEditor.ts
33
*
4-
* IEditor implementation for Neovim
4+
* Editor implementation for Neovim
55
*/
66

77
import * as os from "os"
@@ -66,7 +66,7 @@ import { IThemeMetadata, ThemeManager } from "./../../Services/Themes"
6666
import { TypingPredictionManager } from "./../../Services/TypingPredictionManager"
6767
import { Workspace } from "./../../Services/Workspace"
6868

69-
import { Editor, IEditor } from "./../Editor"
69+
import { Editor } from "./../Editor"
7070

7171
import { BufferManager, IBuffer } from "./../BufferManager"
7272
import { CompletionMenu } from "./CompletionMenu"
@@ -99,7 +99,7 @@ import { CanvasRenderer } from "../../Renderer/CanvasRenderer"
9999
import { WebGLRenderer } from "../../Renderer/WebGL/WebGLRenderer"
100100
import { getInstance as getNotificationsInstance } from "./../../Services/Notifications"
101101

102-
export class NeovimEditor extends Editor implements IEditor {
102+
export class NeovimEditor extends Editor implements Oni.Editor {
103103
private _bufferManager: BufferManager
104104
private _neovimInstance: NeovimInstance
105105
private _renderer: INeovimRenderer

browser/src/Editor/OniEditor/OniEditor.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* OniEditor.ts
33
*
4-
* IEditor implementation for Oni
4+
* Editor implementation for Oni
55
*
66
* Extends the capabilities of the NeovimEditor
77
*/
@@ -41,8 +41,6 @@ import { ThemeManager } from "./../../Services/Themes"
4141
import { TokenColors } from "./../../Services/TokenColors"
4242
import { Workspace } from "./../../Services/Workspace"
4343

44-
import { IEditor } from "./../Editor"
45-
4644
import { BufferScrollBarContainer } from "./containers/BufferScrollBarContainer"
4745
import { DefinitionContainer } from "./containers/DefinitionContainer"
4846
import { ErrorsContainer } from "./containers/ErrorsContainer"
@@ -64,7 +62,7 @@ const wrapReactComponentWithLayer = (id: string, component: JSX.Element): Oni.Bu
6462
}
6563
}
6664

67-
export class OniEditor extends Utility.Disposable implements IEditor {
65+
export class OniEditor extends Utility.Disposable implements Oni.Editor {
6866
private _neovimEditor: NeovimEditor
6967

7068
public get mode(): string {

browser/src/Plugins/Api/Oni.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ import { inputManager } from "./../../Services/InputManager"
2727
import * as LanguageManager from "./../../Services/Language"
2828
import { getTutorialManagerInstance } from "./../../Services/Learning"
2929
import { getInstance as getAchievementsInstance } from "./../../Services/Learning/Achievements"
30-
import {
31-
getInstance as getMenuManagerInstance,
32-
IMenuOptionWithHighlights,
33-
} from "./../../Services/Menu"
30+
import { getInstance as getMenuManagerInstance } from "./../../Services/Menu"
3431
import { getInstance as getFiltersInstance } from "./../../Services/Menu/Filter"
3532
import { getInstance as getNotificationsInstance } from "./../../Services/Notifications"
3633
import { getInstance as getOverlayInstance } from "./../../Services/Overlay"
@@ -47,35 +44,8 @@ import { Search } from "./../../Services/Search/SearchProvider"
4744

4845
import * as throttle from "lodash/throttle"
4946

50-
import { ISearch } from "./Search" // TODO: Move to oni-api
51-
5247
const react = require("react") // tslint:disable-line no-var-requires
5348

54-
// TODO: Move to oni-api
55-
export interface QuickFixEntry {
56-
filename: string
57-
lnum: number
58-
col: number
59-
text: string
60-
}
61-
62-
// TODO: Move to oni-api under `menu`
63-
export type IMenuFilter = (options: any[], searchString: string) => IMenuOptionWithHighlights[]
64-
65-
// TODO: Move to oni-api under `menu`
66-
export interface IMenuFilters {
67-
getDefault(): IMenuFilter
68-
getByName(name: string): IMenuFilter
69-
}
70-
71-
export interface ApiNext {
72-
search: ISearch
73-
ui: Ui
74-
filter: IMenuFilters // TODO: Move to oni-api under menu
75-
76-
populateQuickFix(entries: QuickFixEntry[]): void
77-
}
78-
7949
export class Dependencies {
8050
public get React(): any {
8151
return react
@@ -89,7 +59,7 @@ const helpers = {
8959
/**
9060
* API instance for interacting with OniApi (and vim)
9161
*/
92-
export class Oni implements OniApi.Plugin.Api, ApiNext {
62+
export class Oni implements OniApi.Plugin.Api {
9363
private _dependencies: Dependencies
9464
private _ui: Ui
9565
private _services: Services
@@ -158,7 +128,7 @@ export class Oni implements OniApi.Plugin.Api, ApiNext {
158128
return getMenuManagerInstance()
159129
}
160130

161-
public get filter(): IMenuFilters {
131+
public get filter(): OniApi.Menu.IMenuFilters {
162132
return getFiltersInstance("") // TODO: Pass either "core" or plugin's name
163133
}
164134

@@ -218,7 +188,7 @@ export class Oni implements OniApi.Plugin.Api, ApiNext {
218188
return helpers
219189
}
220190

221-
public get search(): ISearch {
191+
public get search(): OniApi.Search.ISearch {
222192
return new Search()
223193
}
224194

@@ -228,7 +198,7 @@ export class Oni implements OniApi.Plugin.Api, ApiNext {
228198
this._services = new Services()
229199
}
230200

231-
public populateQuickFix(entries: QuickFixEntry[]): void {
201+
public populateQuickFix(entries: OniApi.QuickFixEntry[]): void {
232202
const neovim: any = editorManager.activeEditor.neovim
233203
neovim.quickFix.setqflist(entries, "Search Results")
234204
neovim.command(":copen")

browser/src/Plugins/Api/Search.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

browser/src/Plugins/Api/Ui.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import * as Oni from "oni-api"
2+
13
import { getFileIcon } from "../../Services/FileIcon"
24
import { getInstance } from "../../Services/IconThemes"
35
import { Icon, IconProps, IconSize } from "../../UI/Icon"
46

5-
export class Ui {
7+
export class Ui implements Oni.Ui.IUi {
68
constructor(private _react: any) {}
79

810
public createIcon(props: IconProps): any {

browser/src/Services/EditorManager.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import * as Oni from "oni-api"
1212
import { Event, IDisposable, IEvent } from "oni-types"
1313

14+
import * as types from "vscode-languageserver-types"
15+
1416
import { remote } from "electron"
1517

1618
export class EditorManager implements Oni.EditorManager {
@@ -123,6 +125,14 @@ class AnyEditorProxy implements Oni.Editor {
123125
return this._activeEditor.activeBuffer
124126
}
125127

128+
public init(filesToOpen: string[]): void {
129+
if (!this._activeEditor) {
130+
return
131+
}
132+
133+
this._activeEditor.init(filesToOpen)
134+
}
135+
126136
public get neovim(): Oni.NeovimEditorCapability {
127137
if (!this._activeEditor) {
128138
return null
@@ -181,6 +191,22 @@ class AnyEditorProxy implements Oni.Editor {
181191
return this._activeEditor.setTextOptions(options)
182192
}
183193

194+
public render(): JSX.Element {
195+
if (!this._activeEditor) {
196+
return null
197+
}
198+
199+
return this._activeEditor.render()
200+
}
201+
202+
public setSelection(selectionRange: types.Range): Promise<void> {
203+
if (!this._activeEditor) {
204+
return null
205+
}
206+
207+
return this._activeEditor.setSelection(selectionRange)
208+
}
209+
184210
/**
185211
* Internal methods
186212
*/
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// import * as Oni from "oni-api"
2-
import * as OniNext from "../../../Plugins/Api/Oni"
1+
import * as Oni from "oni-api"
32

43
import { filter as fuseFilter } from "./FuseFilter"
54
import { filter as noFilter } from "./NoFilter"
65
import { filter as RegExFilter } from "./RegExFilter"
76
import { filter as vscodeFilter } from "./VSCodeFilter"
87

9-
class Filters implements OniNext.IMenuFilters {
10-
private _filters = new Map<string, OniNext.IMenuFilter>()
8+
class Filters implements Oni.Menu.IMenuFilters {
9+
private _filters = new Map<string, Oni.Menu.IMenuFilter>()
1110

1211
constructor() {
1312
this._filters
@@ -18,11 +17,11 @@ class Filters implements OniNext.IMenuFilters {
1817
.set("vscode", vscodeFilter)
1918
}
2019

21-
public getDefault(): OniNext.IMenuFilter {
20+
public getDefault(): Oni.Menu.IMenuFilter {
2221
return this.getByName("default")
2322
}
2423

25-
public getByName(name: string): OniNext.IMenuFilter {
24+
public getByName(name: string): Oni.Menu.IMenuFilter {
2625
return this._filters.has(name) ? this._filters.get(name) : this.getDefault()
2726
}
2827

@@ -31,6 +30,6 @@ class Filters implements OniNext.IMenuFilters {
3130

3231
const _instance = new Filters()
3332

34-
export function getInstance(owner: string): OniNext.IMenuFilters {
33+
export function getInstance(owner: string): Oni.Menu.IMenuFilters {
3534
return _instance
3635
}

browser/src/Services/Search/SearchPaneView.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Entry point for search-related features
55
*/
66

7+
import * as Oni from "oni-api"
78
import * as React from "react"
89

910
import { IDisposable, IEvent } from "oni-types"
@@ -12,8 +13,6 @@ import { Workspace } from "./../Workspace"
1213

1314
export * from "./SearchProvider"
1415

15-
import * as SearchApi from "./../../Plugins/Api/Search" // TODO: Import oni-api instead
16-
1716
import styled from "styled-components"
1817
import { SearchTextBox } from "./SearchTextBox"
1918

@@ -31,7 +30,7 @@ export interface ISearchPaneViewProps {
3130
onFocus: IEvent<void>
3231
focusImmediately?: boolean
3332

34-
onSearchOptionsChanged: (opts: SearchApi.Options) => void
33+
onSearchOptionsChanged: (opts: Oni.Search.Options) => void
3534
}
3635

3736
export interface ISearchPaneViewState {

0 commit comments

Comments
 (0)