Browse Source

Fix project not found when `project.godot` file is excluded (#635)

* Fix project not found when `project.godot` file is excluded

* Ignore user excludes when using workspace.findFiles

* Fix linter warnings

---------

Co-authored-by: David Kincaid <[email protected]>
InfiniteXyy 1 year ago
parent
commit
a9508d965d
2 changed files with 10 additions and 10 deletions
  1. 7 7
      src/utils/index.ts
  2. 3 3
      src/utils/project_utils.ts

+ 7 - 7
src/utils/index.ts

@@ -15,13 +15,13 @@ export function is_debug_mode(): boolean {
 export async function find_file(file: string): Promise<vscode.Uri | null> {
 	if (fs.existsSync(file)) {
 		return vscode.Uri.file(file);
-	} else {
-		const fileName = path.basename(file);
-		const results = await vscode.workspace.findFiles("**/" + fileName);
-		if (results.length == 1) {
-			return results[0];
-		}
 	}
+	const fileName = path.basename(file);
+	const results = await vscode.workspace.findFiles(`**/${fileName}`, null);
+	if (results.length === 1) {
+		return results[0];
+	}
+	
 	return null;
 }
 
@@ -38,7 +38,7 @@ export async function get_free_port(): Promise<number> {
 export function make_docs_uri(path: string, fragment?: string) {
 	return vscode.Uri.from({
 		scheme: "gddoc",
-		path: path + ".gddoc",
+		path: `${path}.gddoc`,
 		fragment: fragment,
 	});
 }

+ 3 - 3
src/utils/project_utils.ts

@@ -9,11 +9,11 @@ let projectFile: string | undefined = undefined;
 export async function get_project_dir(): Promise<string | undefined> {
 	let file = "";
 	if (vscode.workspace.workspaceFolders !== undefined) {
-		const files = await vscode.workspace.findFiles("**/project.godot");
+		const files = await vscode.workspace.findFiles("**/project.godot", null);
 
 		if (files.length === 0) {
 			return undefined;
-		} 
+		}
 		if (files.length === 1) {
 			file = files[0].fsPath;
 			if (!fs.existsSync(file) || !fs.statSync(file).isFile()) {
@@ -77,7 +77,7 @@ export function find_project_file(start: string, depth: number = 20) {
 	if (start === ".") {
 		if (fs.existsSync("project.godot") && fs.statSync("project.godot").isFile()) {
 			return "project.godot";
-		} 
+		}
 		return null;
 	}
 	const folder = path.dirname(start);