Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
kat0h committed Nov 24, 2021
1 parent a83ae78 commit 9f39a06
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Commands:
```

Open preview window automatically:

```vim
augroup bufpreview
autocmd!
Expand Down
10 changes: 5 additions & 5 deletions denops/bufpreview/@renderer/markdown/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Denops, Renderer, op } from "../../lib/deps.ts";
import { Denops, op, Renderer } from "../../lib/deps.ts";

export default class Markdown extends Renderer {
constructor(denops: Denops) {
super(denops)
super(denops);
}

get rendererClientHTML() {
Expand All @@ -12,12 +12,12 @@ export default class Markdown extends Renderer {
}

async avaiableRenderer() {
const ret = (await op.filetype.get(this._denops)) == "markdown"
return ret
const ret = (await op.filetype.get(this._denops)) == "markdown";
return ret;
}

data() {
return {}
return {};
}

dataFromClient(_) {}
Expand Down
16 changes: 8 additions & 8 deletions denops/bufpreview/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class Server {
private _denops: Denops;
private _bufnr: number;
private _onClose: () => void;
private _renderer: Renderer
private _renderer: Renderer;

private _buffer: Buffer;
private _listener: Deno.Listener | undefined;
Expand All @@ -25,15 +25,15 @@ export default class Server {
// サーバ側で通信が切断された時に呼ばれます
onClose: () => void,
// レンダラー
renderer: Renderer
renderer: Renderer,
) {
this._denops = denops;
this._bufnr = bufnr;
this._onClose = onClose;
this._renderer = renderer
this._renderer = renderer;

// TODO: 消す
this._renderer.avaiableRenderer()
this._renderer.avaiableRenderer();

this._buffer = new Buffer(denops, this._bufnr);

Expand All @@ -53,7 +53,7 @@ export default class Server {
cursorLine: {
linePos: buffer.cursorline,
bufLengh: buffer.lines.length,
data: this._renderer.data("cursorMoved")
data: this._renderer.data("cursorMoved"),
},
};
this._sockets.forEach((socket) => {
Expand All @@ -64,13 +64,13 @@ export default class Server {
// バッファが削除された時
this._buffer.events.on("bufDelete", (_) => {
const data = {
data: this._renderer.data("bufDelete")
}
data: this._renderer.data("bufDelete"),
};
this.close();
});

// クライアント
this._body = this._renderer.rendererClientHTML
this._body = this._renderer.rendererClientHTML;
}

run(host: string, port: number) {
Expand Down
10 changes: 5 additions & 5 deletions denops/bufpreview/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Denops } from "./deps.ts"
import { Denops } from "./deps.ts";

type JsonPrimitive =
| boolean
Expand All @@ -15,15 +15,15 @@ type Json = JsonPrimitive | JsonArray | JsonObject;
type Autocmd =
| "textChenged"
| "cursorMoved"
| "bufDelete"
| "bufDelete";

// レンダラー
// denopsが渡される
export abstract class Renderer {
private _denops
private _denops;

constructor (denops: Denops) {
this._denops = denops
constructor(denops: Denops) {
this._denops = denops;
}
// クライアントのHTML
abstract get rendererClientHTML(): string;
Expand Down
17 changes: 14 additions & 3 deletions denops/bufpreview/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { Denops, ensureString, fn, op, open, vars, Renderer } from "./lib/deps.ts";
import {
Denops,
ensureString,
fn,
op,
open,
Renderer,
vars,
} from "./lib/deps.ts";

import Server from "./lib/server.ts";

// 一度に開けるサーバーは一つ
let server: Server | undefined;

const Markdown = (await import((new URL("./@renderer/markdown/main.ts", import.meta.url)).href)).default
const Markdown =
(await import(
(new URL("./@renderer/markdown/main.ts", import.meta.url)).href
)).default;

export function main(denops: Denops) {
denops.dispatcher = {
Expand All @@ -30,7 +41,7 @@ export function main(denops: Denops) {
// サーバーを開く
const openServer = async () => {
// レンダラー
const renderer = new Markdown(denops)
const renderer = new Markdown(denops);
// サーバーが既に開かれているなら
if (server != undefined) {
server.close();
Expand Down

0 comments on commit 9f39a06

Please sign in to comment.