Skip to content

Commit

Permalink
fix: unused global search for build binaries vknabel/vscode-swiftform…
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Jun 22, 2024
1 parent 268d4f0 commit 8a7b908
Showing 1 changed file with 20 additions and 16 deletions.
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

0 comments on commit 8a7b908

Please sign in to comment.