Skip to content

Commit

Permalink
fix(types): add Promisify type to neovim APIs #265
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong authored Dec 3, 2023
1 parent ea95e0d commit 6020a11
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/neovim/src/api/Buffer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseApi } from './Base';
import { ExtType, Metadata } from './types';
import { ExtType, Metadata, Promisify } from './types';

export interface BufferSetLines {
start?: number;
Expand Down Expand Up @@ -383,4 +383,4 @@ export class Buffer extends BaseApi {
}
}

export interface AsyncBuffer extends Buffer, Promise<Buffer> {}
export interface AsyncBuffer extends Promisify<Buffer>, Promise<Buffer> {}
3 changes: 2 additions & 1 deletion packages/neovim/src/api/Neovim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ export class Neovim extends BaseApi {
* @param {Window} Window handle
*/
set window(win: AsyncWindow) {
this.setWindow(win);
if (win instanceof Window) this.setWindow(win);
else win.then(win => this.setWindow(win));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/neovim/src/api/Tabpage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseApi } from './Base';
import { ExtType, Metadata } from './types';
import { ExtType, Metadata, Promisify } from './types';
import { createChainableApi } from './helpers/createChainableApi';
import { Window, AsyncWindow } from './Window';

Expand Down Expand Up @@ -40,4 +40,4 @@ export class Tabpage extends BaseApi {
}
}

export interface AsyncTabpage extends Tabpage, Promise<Tabpage> {}
export interface AsyncTabpage extends Promisify<Tabpage>, Promise<Tabpage> {}
4 changes: 2 additions & 2 deletions packages/neovim/src/api/Window.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseApi } from './Base';
import { ExtType, Metadata } from './types';
import { ExtType, Metadata, Promisify } from './types';
import { createChainableApi } from './helpers/createChainableApi';
import { Tabpage, AsyncTabpage } from './Tabpage';
import { Buffer, AsyncBuffer } from './Buffer';
Expand Down Expand Up @@ -118,4 +118,4 @@ export class Window extends BaseApi {
}
}

export interface AsyncWindow extends Window, Promise<Window> {}
export interface AsyncWindow extends Promisify<Window>, Promise<Window> {}
4 changes: 4 additions & 0 deletions packages/neovim/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ export const Metadata: MetadataType[] = [
prefix: 'nvim_tabpage_',
},
];

export type Promisify<T> = {
[K in keyof T]: Promise<T[K]>;
};

0 comments on commit 6020a11

Please sign in to comment.