-
Notifications
You must be signed in to change notification settings - Fork 669
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
wip: feat: Make foam respect the .gitignore file #1413
base: master
Are you sure you want to change the base?
Changes from 3 commits
74dc6c1
68d2d37
cf9a173
bd3051a
ed3b0ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { isEmpty } from 'lodash'; | ||
import { isEmpty, map, compact, filter, split, startsWith } from 'lodash'; | ||
import { | ||
EndOfLine, | ||
FileType, | ||
|
@@ -25,6 +25,8 @@ import { | |
IDataStore, | ||
IMatcher, | ||
} from '../core/services/datastore'; | ||
import * as path from 'path'; | ||
import { Logger } from '../core/utils/log'; | ||
|
||
interface SelectionInfo { | ||
document: TextDocument; | ||
|
@@ -201,6 +203,29 @@ export async function createMatcherAndDataStore(excludes: string[]): Promise<{ | |
const excludePatterns = new Map<string, string[]>(); | ||
workspace.workspaceFolders.forEach(f => excludePatterns.set(f.name, [])); | ||
|
||
Logger.info('[wtw] Excluded patterns from settings: ' + excludes); | ||
// Read .gitignore files and add patterns to excludePatterns | ||
for (const folder of workspace.workspaceFolders) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this block of code should live here, I would have it together with the rest of the configuration, in order to populate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll rework it later, can you hint me more about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry what do you mean? My understanding is that your blocker is only the notification to the user not working (and unfortunately I can't understand why that's the case) - am I missing something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yes, I was so blocked in the |
||
const gitignoreUri = Uri.joinPath(folder.uri, '.gitignore'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path needs to be the same as the file(s) you are watching for changes. (this should be easy to do if you have both at the top level).
|
||
try { | ||
await workspace.fs.stat(gitignoreUri); // Check if the file exists | ||
const gitignoreContent = await workspace.fs.readFile(gitignoreUri); // Read the file content | ||
const patterns = map( | ||
filter( | ||
split(Buffer.from(gitignoreContent).toString('utf-8'), '\n'), | ||
line => line && !startsWith(line, '#') | ||
), | ||
line => line.trim() | ||
); | ||
excludePatterns.get(folder.name).push(...compact(patterns)); | ||
|
||
Logger.info(`Excluded patterns from ${gitignoreUri.path}: ${patterns}`); | ||
} catch (error) { | ||
// .gitignore file does not exist, continue | ||
Logger.error(`Error reading .gitignore file: ${error}`); | ||
} | ||
} | ||
|
||
for (const exclude of excludes) { | ||
const tokens = exclude.split('/'); | ||
const matchesFolder = workspace.workspaceFolders.find( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to live inside
context.subscriptions
so that it's properly cleaned up afterwardsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true! The issue is that the FileSystemWatcher may be disposed if it's not added to context.subscriptions. problem solved.