Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: formatting via lsp is broken for another buffer #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions denops/@lspoints/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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")),
Expand All @@ -49,11 +49,7 @@ export class Extension extends BaseExtension {
if (result == null) {
return;
}
await applyTextEdits(
denops,
Number(bufnr),
result,
);
await applyTextEdits(denops, bufnr, result);
},
});
}
Expand Down