-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
Introduce IRelativePattern and adopt in DocumentFilter/FileWatcher/FileSearch #34695
Conversation
src/vs/vscode.d.ts
Outdated
pattern?: string | WorkspacePattern; | ||
} | ||
|
||
export interface WorkspacePattern { |
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.
jsdoc missing
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.
I wonder if we should also make it a relative pattern as we have in the lower level. A class
like this
class RelativePattern {
base: Uri;
pattern: string;
constructor(pattern:string, base: WorkspaceFolder | Uri)
}
The ctor adds some util-sugar to it and making just a Uri
allows for more generic use in extensions, e.g watch for file event in a certain folder (unrelated to a workspace folder)
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.
Yeah I like that 👍
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.
In addition I would add the type to createFileSystemWatcher. Eg. globPattern: string | RelativePattern
Added my comments |
|
||
export function toLanguageSelector(selector: vscode.DocumentSelector): LanguageSelector { | ||
return selector as LanguageSelector; | ||
} |
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.
Do we actually need this? Is that an URI issue?
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.
@jrieken yeah I think so, now I have to do the same for the watcher:
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.
Try again, I have pushed some changes to URI and it should not be an issue anymore
@dbaeumer @jrieken yeah I like adding this to the file watcher too because we have an actual use case for @joaomoreno who needs to watch per repository. And now with being able to use any I added it via 837ef11 |
That's pretty cool. And I do believe that's how globs are supposed to work anyway. I don't understand why we ever had globs which matched to absolute values. You'll find this pretty much nowhere else. In gulp, globs are always matched to a base. In zsh, they are always matched against the cwd, unless they start with |
|
||
export function toLanguageSelector(selector: vscode.DocumentSelector): LanguageSelector { | ||
return selector as LanguageSelector; | ||
} |
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.
Try again, I have pushed some changes to URI and it should not be an issue anymore
src/vs/vscode.d.ts
Outdated
/** | ||
* A relative glob pattern like `*.{ts,js}`. | ||
*/ | ||
readonly pattern: string; |
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.
Maybe no readonly
for those two?
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.
@jrieken yeah, pushed
src/vs/vscode.d.ts
Outdated
/** | ||
* A base to which the pattern will be matched against relatively. | ||
*/ | ||
readonly base: Uri; |
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.
On a second thought this could also just be a string, right? We have the sugar ctor but technically we aren't globbing against a URI but against it path/fspath?
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.
src/vs/vscode.d.ts
Outdated
* @param maxResults An upper-bound for the result. | ||
* @param token A token that can be used to signal cancellation to the underlying search engine. | ||
* @return A thenable that resolves to an array of resource identifiers. | ||
*/ | ||
export function findFiles(include: string, exclude?: string, maxResults?: number, token?: CancellationToken): Thenable<Uri[]>; | ||
export function findFiles(include: string | RelativePattern, exclude?: string | RelativePattern, maxResults?: number, token?: CancellationToken): Thenable<Uri[]>; |
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.
To avoid repetition we could consider something like
/**
* Write Jsdoc once
*/
type GlobPattern = string | RelativePattern
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.
👍
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.
export class RelativePattern implements IRelativePattern { | ||
base: string; | ||
|
||
constructor(public pattern: string, base: vscode.WorkspaceFolder | string) { |
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.
fugly - mixing properties definitions like that
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.
Yeah, oversight, fixed via 328f82a
@roblourens it seems to me that the include/exclude patterns for Given that, it seems we have a slight inconsistency with how we handle patterns in the API:
This makes it a harder to use the
and then change |
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.
I am happy with the API changes, the rest I didn't really look at
I clarified this in the JSDocs how patterns apply depending on where they are used, I think we should not make this any more complicated by introducing even more types. The reality is that |
Refs: #34157
Creating this for discussion. Idea is to make it easier for extensions to work with patterns that should be relative to the workspace. We typically ask for a string for the
pattern
and now we could add an OR-type for a workspace relative pattern described byWorkspacePattern
. Thepattern
will be matched against the providedbase
folder and can be relative (e.g. not starting with the workspace path or**
).Before doing more polish, @jrieken @dbaeumer for initial input.