Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

1.6 KB
Raw Blame
/** "Mark Directory as" (project view context menu): edits Settings › Project Structure. */
import { call, commands, isTauri } from "@/platform/ipc";
import {
  PROJECT_STRUCTURE_KEYS,
  markFolder,
  rootRole,
  validateProjectStructure,
  type FolderRole,
} from "@/platform/languageSettings";
import { currentDetectedRoots, currentRoots } from "@/platform/projectRoots";
import { loadSettings, relativePath, useProject } from "@/platform/project";

/** Effective role of the folder: marked by the user or detected from a build file. */
export function directoryRole(path: string): FolderRole | null {
  const { project } = useProject.getState();
  if (!project) return null;
  return rootRole(currentRoots(), relativePath(project.root, path));
}

/**
 * Gives `path` the `role` (null = Unmark); written to the project's `.openidea/settings.toml`.
 * Unmarking a root detected from a build file keeps it unmarked across re-detection.
 */
export async function markDirectory(path: string, role: FolderRole | null): Promise<void> {
  const { project, settings } = useProject.getState();
  if (!project || !isTauri()) return;
  const rel = relativePath(project.root, path);
  if (rel === path) return;
  const before = validateProjectStructure(settings?.projectStructure);
  const next = markFolder(before, rel, role, currentDetectedRoots());
  for (const key of PROJECT_STRUCTURE_KEYS) {
    if (JSON.stringify(before[key]) !== JSON.stringify(next[key])) {
      await call(commands.settingsSet("project", `projectStructure.${key}`, JSON.stringify(next[key])));
    }
  }
  await loadSettings();
}