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

Function activate

packages/foam-vscode/src/vscode/features/editing/refactor.ts:18–178  ·  view source on GitHub ↗
(
  context: vscode.ExtensionContext,
  foamPromise: Promise<Foam>
)

Source from the content-addressed store, hash-verified

16 'foam.links.sync.markdownLinkNotificationShown';
17
18export default async function activate(
19 context: vscode.ExtensionContext,
20 foamPromise: Promise<Foam>
21) {
22 const foam = await foamPromise;
23
24 context.subscriptions.push(
25 vscode.workspace.onWillRenameFiles(async e => {
26 if (!getFoamVsCodeConfig<boolean>('links.sync.enable', true)) {
27 return;
28 }
29 const renameEdits = new vscode.WorkspaceEdit();
30 let hasMarkdownBacklinks = false;
31 for (const { oldUri, newUri } of e.files) {
32 const foamOldUri = fromVsCodeUri(oldUri);
33 const foamNewUri = fromVsCodeUri(newUri);
34
35 const isDirectory =
36 (await vscode.workspace.fs.stat(oldUri)).type ===
37 vscode.FileType.Directory;
38
39 const wikilinkEdits = isDirectory
40 ? computeDirectoryWikilinkRenameEdits(
41 foam.workspace,
42 foam.graph,
43 foamOldUri,
44 foamNewUri
45 )
46 : computeWikilinkRenameEdits(
47 foam.workspace,
48 foam.graph,
49 foamOldUri,
50 foamNewUri
51 );
52
53 for (const { uri, edit } of wikilinkEdits) {
54 renameEdits.replace(
55 toVsCodeUri(uri),
56 toVsCodeRange(edit.range),
57 edit.newText
58 );
59 }
60
61 // For directory renames, remove stale workspace entries for files under
62 // the old directory path. On macOS (FSEvents), the file watcher fires
63 // directory-level events rather than per-file events, so Foam never
64 // receives individual delete events for those files. We clean up here,
65 // synchronously, inside the awaited onWillRenameFiles handler, before
66 // VS Code performs the actual rename.
67 if (isDirectory) {
68 const oldDirPath = foamOldUri.path;
69 foam.workspace
70 .list()
71 .filter(r => r.uri.path.startsWith(oldDirPath + '/'))
72 .forEach(resource => foam.workspace.delete(resource.uri));
73 }
74
75 if (!isDirectory) {

Callers

nothing calls this directly

Calls 15

replaceMethod · 0.95
entriesMethod · 0.95
setMethod · 0.95
fromVsCodeUriFunction · 0.90
toVsCodeUriFunction · 0.90
toVsCodeRangeFunction · 0.90
pushMethod · 0.80
getBacklinksMethod · 0.80
thenMethod · 0.80
statMethod · 0.65

Tested by

no test coverage detected