Skip to content

Commit

Permalink
add support for tabs
Browse files Browse the repository at this point in the history
returning to appreciating the formatting loading animation :(
  • Loading branch information
noneofyourbusiness1415252 committed Nov 28, 2023
1 parent b6f08fc commit ea2cd3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis
}

protected onDidChangeConfiguration(params: DidChangeConfigurationParams) {

this.console.log(`Received updated settings`);
if (params?.settings) {
this.defaultClientConfig = params?.settings;
Expand Down Expand Up @@ -848,7 +849,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
10 changes: 5 additions & 5 deletions packages/pyright-yapf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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 All @@ -33,4 +33,4 @@ export function formatBufferWithYapf(buf: string, indentWidth: number): TextEdit
newText: outputString,
},
];
}
}

0 comments on commit ea2cd3e

Please sign in to comment.