Skip to content

Commit

Permalink
Merge pull request #26 from noneofyourbusiness1415252/patch-2-leg
Browse files Browse the repository at this point in the history
respect indent style preference
  • Loading branch information
jackyzha0 authored Nov 29, 2023
2 parents b6f08fc + 1cdc1fe commit dc0cbef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis

const buf = workspace.service.getSourceFile(filePath)?.getOpenFileContents();
if (!buf) return;
return formatBufferWithYapf(buf, params.options.tabSize);
return formatBufferWithYapf(buf, params.options.tabSize, !params.options.insertSpaces);
}

protected async onDeclaration(
Expand Down
12 changes: 8 additions & 4 deletions packages/pyright-yapf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { spawnSync, SpawnSyncReturns } from 'node:child_process';
import { TextEdit, uinteger } from 'vscode-languageserver';

// TODO: there's probably a way to make this async so format requests dont block other requests
function _runYapf(buf: string, indentWidth: number): SpawnSyncReturns<Buffer> {
const args = ['--style', `{based_on_style: pep8, indent_width: ${indentWidth}}`, '--no-local-style'];
function _runYapf(buf: string, indentWidth: number, useTabs: boolean): SpawnSyncReturns<Buffer> {
const args = [
'--style',
`{based_on_style: pep8, indent_width: ${indentWidth}, use_tabs: ${useTabs}}`,
'--no-local-style',
];
return spawnSync(`yapf`, args, {
input: buf,
});
}

export function formatBufferWithYapf(buf: string, indentWidth: number): TextEdit[] {
const outBuf = _runYapf(buf, indentWidth);
export function formatBufferWithYapf(buf: string, indentWidth: number, useTabs: boolean): TextEdit[] {
const outBuf = _runYapf(buf, indentWidth, useTabs);
if (outBuf.error || outBuf.stderr.length > 0) {
console.error(`Error running yapf: ${outBuf.stderr}`);
return [];
Expand Down

0 comments on commit dc0cbef

Please sign in to comment.