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 27, 2023
1 parent b6f08fc commit 71db5c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 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,
},
];
}
}
6 changes: 5 additions & 1 deletion packages/pyright/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = (_, { mode }) => {
timings: true,
},
resolve: {
extensions: ['.ts', '.js'],
extensions: ['.ts', '.js', '.node'],
alias: tsconfigResolveAliases('tsconfig.json'),
},
externals: {
Expand All @@ -61,6 +61,10 @@ module.exports = (_, { mode }) => {
target: 'node12',
},
},
{
test: /\.node$/,
loader: 'node-loader',
}
],
},
plugins: [new CopyPlugin({ patterns: [{ from: typeshedFallback, to: 'typeshed-fallback' }] })],
Expand Down

0 comments on commit 71db5c2

Please sign in to comment.