-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: formatting via lsp is broken for another buffer
- Loading branch information
Showing
1 changed file
with
5 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,16 @@ import { assert, is } from "../lspoints/deps/unknownutil.ts"; | |
import { BaseExtension, type Lspoints } from "../lspoints/interface.ts"; | ||
import { | ||
applyTextEdits, | ||
uriFromBufnr, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
export class Extension extends BaseExtension { | ||
initialize(denops: Denops, lspoints: Lspoints) { | ||
lspoints.defineCommands("format", { | ||
execute: async (bufnr: unknown, timeout = 5000, selector?: unknown) => { | ||
assert(timeout, is.Number); | ||
let clients = lspoints.getClients(Number(bufnr)).filter((c) => | ||
assert(bufnr, is.Number); | ||
let clients = lspoints.getClients(bufnr).filter((c) => | ||
c.serverCapabilities.documentFormattingProvider != null | ||
); | ||
if (is.String(selector)) { | ||
|
@@ -23,14 +25,12 @@ export class Extension extends BaseExtension { | |
throw Error("何のクライアントも選ばれてないわよ"); | ||
} | ||
|
||
const path = String(await denops.call("expand", "%:p")); | ||
|
||
const resultPromise = lspoints.request( | ||
clients[0].name, | ||
"textDocument/formatting", | ||
{ | ||
textDocument: { | ||
uri: "file://" + path, | ||
uri: await uriFromBufnr(denops, bufnr), | ||
}, | ||
options: { | ||
tabSize: Number(await denops.call("shiftwidth")), | ||
|
@@ -49,11 +49,7 @@ export class Extension extends BaseExtension { | |
if (result == null) { | ||
return; | ||
} | ||
await applyTextEdits( | ||
denops, | ||
Number(bufnr), | ||
result, | ||
); | ||
await applyTextEdits(denops, bufnr, result); | ||
}, | ||
}); | ||
} | ||
|