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 random file being chosen to create project #190

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
checkMesonIsConfigured,
getOutputChannel,
relativeBuildDir,
rootMesonFiles,
} from "./utils";
import { DebugConfigurationProviderCppdbg } from "./debug/cppdbg";
import { DebugConfigurationProviderLldb } from "./debug/lldb";
Expand Down Expand Up @@ -38,7 +39,7 @@ export async function activate(ctx: vscode.ExtensionContext) {
}

const root = vscode.workspace.workspaceFolders[0].uri.fsPath;
const mesonFiles = await vscode.workspace.findFiles("**/meson.build");
const mesonFiles = await rootMesonFiles();
if (mesonFiles.length === 0) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,24 @@ export async function useCompileCommands(buildDir: string) {
export function checkMesonIsConfigured(buildDir: string) {
return fs.existsSync(path.join(buildDir, "meson-private", "coredata.dat"));
}

export async function rootMesonFiles(): Promise<vscode.Uri[]> {
const allFiles = (await vscode.workspace.findFiles("**/meson.build")).sort(
(a, b) => a.fsPath.length - b.fsPath.length,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the path lenght in chars? Won't it make a/b/meson.build before long_dir_name/meson.build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you're right. I think I need to sort by file path components

Copy link
Contributor

@wolfpld wolfpld Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the code correctly, I don't think this would be a problem. The path-length check should be sufficient, since there's no scenario in which you would have found a parent-level meson.build after processing a subdirectory of said parent.

);

const rootFiles: vscode.Uri[] = [];
for (const a of allFiles) {
if (rootFiles.length === 0) {
rootFiles.push(a);
continue;
}

if (!path.dirname(a.fsPath).startsWith(path.dirname(rootFiles[rootFiles.length - 1].fsPath))) {
rootFiles.push(a);
continue;
}
}

return rootFiles;
}