-
Notifications
You must be signed in to change notification settings - Fork 666
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 all commits
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ export async function activate(context: ExtensionContext) { | |
exposeLogger(context, logger); | ||
|
||
try { | ||
Logger.info('Starting Foam'); | ||
Logger.info('[wtw] Starting Foam'); | ||
|
||
if (workspace.workspaceFolders === undefined) { | ||
Logger.info('No workspace open. Foam will not start'); | ||
|
@@ -100,6 +100,13 @@ export async function activate(context: ExtensionContext) { | |
'Foam: Reload the window to use the updated settings' | ||
); | ||
} | ||
}), | ||
// 2024-11-25 21:22:48 TODO wip not working as expected | ||
workspace.createFileSystemWatcher('.gitignore').onDidChange(e => { | ||
Logger.info(`[wtw] File changed: ${e.fsPath}`); | ||
window.showInformationMessage( | ||
'Foam: Reload the window to use the updated .gitignore settings' | ||
); | ||
Comment on lines
+103
to
+109
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. @riccardoferretti Hello, based on online searches and AI suggestions, I believe that this approach should be able to achieve the effect of issuing a prompt when modifying the ignore settings. However, when I tested it, I found that it did not take effect. I would like to consult with you to see if you have any experience and can help me identify where I might have gone wrong. 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. Yeah that looks like it should work, I am not really sure why it doesn't... |
||
}) | ||
); | ||
|
||
|
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 |
||
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 afterwards