(
workspaceDir: string,
options: LoadWorkspaceOptions & {
/**
* Optional watcher to keep the in-memory graph in sync with on-disk
* changes. Used by long-running consumers (e.g. the MCP server). One-shot
* commands (most CLI subcommands) leave this undefined and read a snapshot.
*/
watcher?: IWatcher;
} = {}
)
| 126 | } |
| 127 | |
| 128 | export async function loadWorkspaceFromDirectory( |
| 129 | workspaceDir: string, |
| 130 | options: LoadWorkspaceOptions & { |
| 131 | /** |
| 132 | * Optional watcher to keep the in-memory graph in sync with on-disk |
| 133 | * changes. Used by long-running consumers (e.g. the MCP server). One-shot |
| 134 | * commands (most CLI subcommands) leave this undefined and read a snapshot. |
| 135 | */ |
| 136 | watcher?: IWatcher; |
| 137 | } = {} |
| 138 | ) { |
| 139 | const rootDir = path.resolve(workspaceDir); |
| 140 | const rootUri = URI.file(rootDir); |
| 141 | |
| 142 | // Cascade: workspace settings beat built-in defaults. The fallback must be |
| 143 | // a fully-resolved config so every getter has a final answer. User-level |
| 144 | // and env-level cascade layers don't exist today; the only env-driven |
| 145 | // config is the telemetry opt-out, which is read directly in resolveCliReporter. |
| 146 | const workspaceSource = readFoamConfig(rootDir); |
| 147 | const foamConfig = cascadeFoamConfig( |
| 148 | [workspaceSource], |
| 149 | new DefaultFoamConfig() |
| 150 | ); |
| 151 | Config.setDefaultConfig(foamConfig); |
| 152 | |
| 153 | const matcher = new GlobMatcher( |
| 154 | Config.getFilesInclude(), |
| 155 | Config.getFilesExclude(), |
| 156 | rootUri |
| 157 | ); |
| 158 | |
| 159 | const dataStore = new NodeFileDataStore( |
| 160 | rootDir, |
| 161 | [ |
| 162 | ...new Set( |
| 163 | (options.excludedPaths ?? []).map(excludedPath => |
| 164 | path.resolve(excludedPath) |
| 165 | ) |
| 166 | ), |
| 167 | ], |
| 168 | matcher |
| 169 | ); |
| 170 | |
| 171 | const noteExtensions = options.noteExtensions ?? Config.getNotesExtensions(); |
| 172 | const parser = createMarkdownParser(); |
| 173 | const providers = [ |
| 174 | new MarkdownResourceProvider(dataStore, parser, noteExtensions), |
| 175 | new AttachmentResourceProvider(Config.getAttachmentExtensions()), |
| 176 | ]; |
| 177 | |
| 178 | const foam = await bootstrap( |
| 179 | [rootUri], |
| 180 | matcher, |
| 181 | options.watcher, |
| 182 | dataStore, |
| 183 | parser, |
| 184 | providers, |
| 185 | Config.getDefaultNoteExtension(), |
no test coverage detected