Skip to content

Commit 3fd9ddf

Browse files
committed
chore: Use absolute paths for buildifier
This has multiple positive effects: - buildifier can be used on any Starlark file even if not bazel workspace is present - buildifier can be used on standalone files outside your current workspace - buildifier will work robustly for multi-workspace setups Closes #620
1 parent 66dadf3 commit 3fd9ddf

2 files changed

Lines changed: 4 additions & 32 deletions

File tree

src/buildifier/buildifier_diagnostics_manager.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as vscode from "vscode";
16-
import * as path from "path";
1716
import { buildifierLint } from "./buildifier";
18-
import { BazelWorkspaceInfo } from "../bazel";
1917
import { ILogger } from "../extension/logger";
2018

2119
/**
@@ -86,23 +84,11 @@ export class BuildifierDiagnosticsManager implements vscode.Disposable {
8684
if (document.languageId === "starlark") {
8785
this.logger.logDebug(`Updating diagnostics for ${document.uri.fsPath}`);
8886

89-
const workspaceInfo = BazelWorkspaceInfo.fromDocument(document);
90-
if (!workspaceInfo) {
91-
this.logger.logDebug(
92-
"No workspace info found for document",
93-
false,
94-
document.uri.fsPath,
95-
);
96-
return;
97-
}
98-
const workspaceRelativePath = path.relative(
99-
workspaceInfo.bazelWorkspacePath,
100-
document.uri.fsPath,
101-
);
87+
const absolutePath = document.uri.fsPath;
10288

10389
const warnings = await buildifierLint(
10490
document.getText(),
105-
workspaceRelativePath,
91+
absolutePath,
10692
"warn",
10793
);
10894
this.logger.logDebug(`Found ${warnings.length} warnings`);

src/buildifier/buildifier_format_provider.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as vscode from "vscode";
16-
import * as path from "path";
1716
import { buildifierFormat } from "./buildifier";
18-
import { BazelWorkspaceInfo } from "../bazel";
1917
import { getBuildifierFixOnFormat } from "../extension/configuration";
2018
import { ILogger } from "../extension/logger";
2119

@@ -38,23 +36,11 @@ export class BuildifierFormatProvider
3836
this.logger.logDebug(`Formatting document: ${document.uri.fsPath}`);
3937

4038
const fileContent = document.getText();
41-
const workspaceInfo = BazelWorkspaceInfo.fromDocument(document);
42-
if (!workspaceInfo) {
43-
this.logger.logDebug(
44-
"No workspace info found for document during formatting",
45-
false,
46-
document.uri.fsPath,
47-
);
48-
return [];
49-
}
50-
const workspaceRelativePath = path.relative(
51-
workspaceInfo.bazelWorkspacePath,
52-
document.uri.fsPath,
53-
);
39+
const absolutePath = document.uri.fsPath;
5440
try {
5541
const formattedContent = await buildifierFormat(
5642
fileContent,
57-
workspaceRelativePath,
43+
absolutePath,
5844
getBuildifierFixOnFormat(),
5945
);
6046
if (formattedContent === fileContent) {

0 commit comments

Comments
 (0)