Skip to content

Commit

Permalink
docs: format on type vknabel/vscode-swiftformat#42
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Jun 22, 2024
1 parent e4a0fe5 commit bdd7d69
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 48 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@
"format": "prettier --write ./*.json ./**/*.ts"
},
"devDependencies": {
"@types/node": "^10.12.10",
"@types/vscode": "^1.26.0",
"prettier": "^2.4.1",
"typescript": "^4.0.0"
"@types/node": "^18.0.0",
"@types/vscode": "^1.80.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"dependencies": {}
"dependencies": {
"glob": "^10.3.4"
}
}
42 changes: 22 additions & 20 deletions src/Current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import * as vscode from "vscode";
import { url } from "./UrlLiteral";
import { absolutePath } from "./AbsolutePath";
import { existsSync } from "fs";
import { join } from "path";
import * as paths from "path";
import * as glob from "glob";
import * as os from "os";

export function prodEnvironment(): Current {
Expand Down Expand Up @@ -76,31 +77,25 @@ export function prodEnvironment(): Current {
.get("apple-swift-format.onlyEnableWithConfig", false),

swiftFormatPath: (document: vscode.TextDocument) => {
// Grab the project root from the local workspace
const workspace = vscode.workspace.getWorkspaceFolder(document.uri);
if (workspace == null) {
return fallbackGlobalSwiftFormatPath();
}

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

if (existsSync(fullPath)) {
return [absolutePath(fullPath)];
}
}
if (
vscode.workspace
.getConfiguration()
.get("apple-swift-format.onlyEnableOnSwiftPMProjects", false)
) {
return null;
}
// Fall back to global defaults found in settings

return fallbackGlobalSwiftFormatPath();
},
resetSwiftFormatPath: () =>
Expand All @@ -118,7 +113,14 @@ export function prodEnvironment(): Current {
};
}

const fallbackGlobalSwiftFormatPath = (): string[] => {
const fallbackGlobalSwiftFormatPath = (): string[] | null => {
if (
vscode.workspace
.getConfiguration()
.get("apple-swift-format.onlyEnableOnSwiftPMProjects", false)
) {
return null;
}
var path = vscode.workspace
.getConfiguration()
.get<string[] | string | null>("apple-swift-format.path", null);
Expand Down
13 changes: 9 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"target": "ES2015",
"outDir": "out",
"lib": ["es6"],
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": ".",
"strictNullChecks": true
},
"exclude": ["node_modules", ".vscode-test"]
}
"exclude": [
"node_modules",
".vscode-test"
]
}
Loading

0 comments on commit bdd7d69

Please sign in to comment.