MCPcopy
hub / github.com/foambubble/foam / loadWorkspaceFromDirectory

Function loadWorkspaceFromDirectory

packages/foam-cli/src/support/filesystem.ts:128–196  ·  view source on GitHub ↗
(
  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;
  } = {}
)

Source from the content-addressed store, hash-verified

126}
127
128export 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(),

Callers 15

runGrepCommandFunction · 0.90
runListCommandFunction · 0.90
runMcpCommandFunction · 0.90
runNoteCommandFunction · 0.90
runLinksCommandFunction · 0.90
runGraphCommandFunction · 0.90
runQueryCommandFunction · 0.90
runLintCommandFunction · 0.90
runSearchCommandFunction · 0.90
runPublishCommandFunction · 0.90
runTagCommandFunction · 0.90
runOutlineCommandFunction · 0.90

Calls 13

readFoamConfigFunction · 0.90
cascadeFoamConfigFunction · 0.90
createMarkdownParserFunction · 0.90
bootstrapFunction · 0.90
fileMethod · 0.80
setDefaultConfigMethod · 0.80
resolveMethod · 0.65
getFilesIncludeMethod · 0.65
getFilesExcludeMethod · 0.65
mapMethod · 0.65
getNotesExtensionsMethod · 0.65

Tested by

no test coverage detected