From ea2cd3e88286c50ae17e5403bff94eea820b5189 Mon Sep 17 00:00:00 2001 From: Umar <80610051+noneofyourbusiness1415252@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:07:01 +0000 Subject: [PATCH] add support for tabs returning to appreciating the formatting loading animation :( --- packages/pyright-internal/src/languageServerBase.ts | 3 ++- packages/pyright-yapf/index.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/pyright-internal/src/languageServerBase.ts b/packages/pyright-internal/src/languageServerBase.ts index 2b6a80cbb..5ef5f5662 100644 --- a/packages/pyright-internal/src/languageServerBase.ts +++ b/packages/pyright-internal/src/languageServerBase.ts @@ -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; @@ -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( diff --git a/packages/pyright-yapf/index.ts b/packages/pyright-yapf/index.ts index 19a953f7c..530fc4df7 100644 --- a/packages/pyright-yapf/index.ts +++ b/packages/pyright-yapf/index.ts @@ -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 { - const args = ['--style', `{based_on_style: pep8, indent_width: ${indentWidth}}`, '--no-local-style']; +function _runYapf(buf: string, indentWidth: number, useTabs: boolean): SpawnSyncReturns { + 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 []; @@ -33,4 +33,4 @@ export function formatBufferWithYapf(buf: string, indentWidth: number): TextEdit newText: outputString, }, ]; -} +} \ No newline at end of file