-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68c5e44
commit 3ad488d
Showing
8 changed files
with
779 additions
and
2,009 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
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 |
---|---|---|
@@ -1,38 +1,25 @@ | ||
import { TextEdit, uinteger } from 'vscode-languageserver'; | ||
import { writeFile, open } from "fs/promises"; | ||
import { interpreter, PyModule } from "node-calls-python"; | ||
let yapf: PyModule; | ||
const YAPF_CONF = `[style] | ||
indent_width: `; | ||
const style_config = "/dev/shm/yapf.ini"; | ||
(async()=>{yapf = await interpreter.import("yapf.yapflib.yapf_api", false); | ||
await writeFile(style_config, YAPF_CONF);})(); | ||
async function _runYapf(buf: string, indentWidth: number, useTabs: boolean): Promise<string[]> { | ||
const handle = await open(style_config, "a+"); | ||
await handle.truncate(YAPF_CONF.length); | ||
await handle.write(`${indentWidth}`); | ||
if (useTabs) | ||
await handle.write(` | ||
use_tabs: true`); | ||
return interpreter.call(yapf, "FormatCode", buf, {style_config, __kwargs: true}) as unknown as string[]; | ||
} | ||
export async function formatBufferWithYapf(buf: string, indentWidth: number, useTabs: boolean): Promise<TextEdit[]> { | ||
const [newText, changed] = await _runYapf(buf, indentWidth, useTabs); | ||
const changes = []; | ||
if (changed) | ||
changes.push({ | ||
// range may seem sus but this is what the official ruff lsp actually does https://github.com/astral-sh/ruff-lsp/blob/main/ruff_lsp/server.py#L735-L740 | ||
range: { | ||
start: { | ||
line: 0, | ||
character: 0, | ||
}, | ||
end: { | ||
line: uinteger.MAX_VALUE, | ||
character: 0, | ||
}, | ||
}, | ||
newText, | ||
}) | ||
return changes; | ||
import { readFile } from "fs/promises"; | ||
import init, { format } from "@wasm-fmt/ruff_fmt"; | ||
/** @deprecated formatBuffer */ | ||
export const formatBufferWithYapf = formatBuffer; | ||
export async function formatBuffer(buf: string, indent_width: number, useTabs: boolean): Promise<TextEdit[]> { | ||
const newText = format(buf, "", { | ||
indent_style: useTabs? "tab" : "space", indent_width }); | ||
return [ | ||
{ | ||
// range may seem sus but this is what the official ruff lsp actually does https://github.com/astral-sh/ruff-lsp/blob/main/ruff_lsp/server.py#L735-L740 | ||
range: { | ||
start: { | ||
line: 0, | ||
character: 0, | ||
}, | ||
end: { | ||
line: uinteger.MAX_VALUE, | ||
character: 0, | ||
}, | ||
}, | ||
newText, | ||
}, | ||
]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"target": "es2017", | ||
"compilerOptions": { | ||
"outDir": "./out" | ||
}, | ||
|
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
Oops, something went wrong.