Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unused global search for build binaries #92

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/Current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import * as vscode from "vscode";
import { url } from "./UrlLiteral";
import { absolutePath } from "./AbsolutePath";
import { existsSync } from "fs";
import { join } from "path";
import { glob } from "glob";
import * as paths from "path";
import * as glob from "glob";

export function prodEnvironment(): Current {
return {
Expand Down Expand Up @@ -100,31 +100,27 @@ export function prodEnvironment(): Current {
.getConfiguration()
.get("swiftlint.autoLintWorkspace", true),
swiftLintPath: (uri: vscode.Uri) => {
// Grab the project root from the local workspace
const workspace = vscode.workspace.getWorkspaceFolder(uri);
if (workspace == null) {
return fallbackGlobalSwiftLintPath();
}

// Support running from Swift PM projects
const possibleLocalPaths = glob.sync(
"**/.build/{release,debug}/swiftlint",
{ maxDepth: 5 }
);
for (const path of possibleLocalPaths) {
// Grab the project root from the local workspace
const workspace = vscode.workspace.getWorkspaceFolder(uri);
if (workspace === null) {
continue;
}
const fullPath = workspace ? join(workspace!.uri.path, path) : path;
const fullPath = workspace
? paths.resolve(workspace!.uri.path, path)
: path;

if (existsSync(fullPath)) {
return [absolutePath(fullPath)];
}
}

if (
vscode.workspace
.getConfiguration()
.get("swiftlint.onlyEnableOnSwiftPMProjects", false)
) {
return null;
}
// Fall back to global defaults found in settings
return fallbackGlobalSwiftLintPath();
},
Expand Down Expand Up @@ -161,7 +157,15 @@ export function prodEnvironment(): Current {
};
}

const fallbackGlobalSwiftLintPath = (): string[] => {
const fallbackGlobalSwiftLintPath = (): string[] | null => {
if (
vscode.workspace
.getConfiguration()
.get("swiftlint.onlyEnableOnSwiftPMProjects", false)
) {
return null;
}

var path = vscode.workspace
.getConfiguration()
.get<string | string[] | null>("swiftlint.path", null);
Expand Down