diff --git a/stylua-vscode/CHANGELOG.md b/stylua-vscode/CHANGELOG.md index 842b0c1e..e23600cc 100644 --- a/stylua-vscode/CHANGELOG.md +++ b/stylua-vscode/CHANGELOG.md @@ -11,6 +11,11 @@ To view the changelog of the StyLua binary, see [here](https://github.com/Johnny ## [Unreleased] +### Changed + +- The VSCode extension will now defer to using `stylua` itself to determine ignores and other configuration, rather than rolling its own ignore system +- The VSCode extension now passes `--stdin-filepath` and `--respect-ignores` to the command line + ## [1.6.3] - 2024-01-06 ### Fixed diff --git a/stylua-vscode/package-lock.json b/stylua-vscode/package-lock.json index 294acac7..d5800720 100644 --- a/stylua-vscode/package-lock.json +++ b/stylua-vscode/package-lock.json @@ -9,7 +9,6 @@ "version": "1.6.3", "license": "MPL-2.0", "dependencies": { - "ignore": "^5.1.8", "node-fetch": "^2.6.1", "semver": "^7.5.4", "unzipper": "^0.10.14", @@ -2165,6 +2164,7 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", + "dev": true, "engines": { "node": ">= 4" } @@ -5599,7 +5599,8 @@ "ignore": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", - "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==" + "integrity": "sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg==", + "dev": true }, "immediate": { "version": "3.0.6", diff --git a/stylua-vscode/package.json b/stylua-vscode/package.json index c767b21c..8b544f4a 100644 --- a/stylua-vscode/package.json +++ b/stylua-vscode/package.json @@ -166,7 +166,6 @@ "webpack-cli": "^4.9.2" }, "dependencies": { - "ignore": "^5.1.8", "node-fetch": "^2.6.1", "semver": "^7.5.4", "unzipper": "^0.10.14", diff --git a/stylua-vscode/src/extension.ts b/stylua-vscode/src/extension.ts index 18e0ca19..8383175a 100644 --- a/stylua-vscode/src/extension.ts +++ b/stylua-vscode/src/extension.ts @@ -1,6 +1,6 @@ import * as vscode from "vscode"; import * as semver from "semver"; -import { formatCode, checkIgnored } from "./stylua"; +import { formatCode } from "./stylua"; import { GitHub, GitHubRelease } from "./github"; import { ResolveMode, StyluaDownloader, StyluaInfo } from "./download"; import { getDesiredVersion } from "./util"; @@ -241,16 +241,14 @@ export async function activate(context: vscode.ExtensionContext) { ); const cwd = currentWorkspace?.uri?.fsPath; - if (await checkIgnored(document.uri, currentWorkspace?.uri)) { - return []; - } - const text = document.getText(); try { const formattedText = await formatCode( + outputChannel, styluaBinaryPath.path, text, + document.uri.fsPath, cwd, byteOffset(document, range.start), byteOffset(document, range.end) diff --git a/stylua-vscode/src/stylua.ts b/stylua-vscode/src/stylua.ts index ba360b9b..f8841616 100644 --- a/stylua-vscode/src/stylua.ts +++ b/stylua-vscode/src/stylua.ts @@ -1,42 +1,23 @@ import * as vscode from "vscode"; import { spawn, exec } from "child_process"; -import ignore from "ignore"; -import { fileExists } from "./util"; - -export async function checkIgnored( - filePath?: vscode.Uri, - currentWorkspace?: vscode.Uri -): Promise { - if (!filePath || !currentWorkspace) { - return false; - } - - const ignoreFilePath = vscode.Uri.joinPath(currentWorkspace, ".styluaignore"); - if (await fileExists(ignoreFilePath)) { - try { - const contents = await vscode.workspace.fs.readFile(ignoreFilePath); - const ig = ignore().add(contents.toString()); - return ig.ignores(vscode.workspace.asRelativePath(filePath)); - } catch (err) { - vscode.window.showErrorMessage( - `Could not read StyLua ignore file at ${ignoreFilePath}:\n${err}` - ); - return false; - } - } - - return false; -} export function formatCode( + outputChannel: vscode.LogOutputChannel, path: string, code: string, + filePath?: string, cwd?: string, startPos?: number, endPos?: number ): Promise { return new Promise((resolve, reject) => { - const args = []; + const args = ["--respect-ignores"]; + + if (filePath) { + args.push("--stdin-filepath"); + args.push(filePath); + } + if (startPos) { args.push("--range-start"); args.push(startPos.toString()); @@ -65,6 +46,8 @@ export function formatCode( args.push("-"); + outputChannel.debug(`${path} {args.join(" ")}`); + const child = spawn(`${path}`, args, { cwd, });