-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
[grammar-finder] Add new Core Package #909
base: master
Are you sure you want to change the base?
Conversation
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.
Some suggestions for the prose. I’ll make broader suggestions in a follow-up comment.
A couple things:
|
@savetheclocktower I appreciate the extremely well thought out review and questions here, and I'll go ahead and address what I can think of right away, but otherwise will likely need to think a bit on a few of these. For your questions on behaviors I want to quickly draw the distinction between the Command Palette invocation of this package and the When
|
Co-authored-by: Andrew Dupont <[email protected]>
Co-authored-by: Andrew Dupont <[email protected]>
Co-authored-by: Andrew Dupont <[email protected]>
Co-authored-by: Andrew Dupont <[email protected]>
Co-authored-by: Andrew Dupont <[email protected]>
Co-authored-by: Andrew Dupont <[email protected]>
Alright, added your suggestions as well as made one small change: I like what you said about trying not to prompt twice, so I've added a very simple implementation for this. In a local non-cached variable we track every extension AutoFind prompts for. Then we don't prompt if the extension is on that list. So that in the event the user opens an unrecognized file then closes it and opens again, they won't get two of the same notification. Or if they open multiple of the same kind of file they won't get a prompt for every single one. Hopefully this can cull the lowest hanging fruit to this problem |
On the topic of "known plaintext files" how does/should it behave with files that have no extension - common for Linux config files. There is also one format I can imagine could both be annoying and useful at the same time which would be for |
Co-authored-by: Daeraxa <[email protected]>
@Daeraxa For files that have no extension, it will end up looking at the name of the file for the extension. This is because of how NodeJS's Take for example the following:
Here I'd personally say that the extension is Which will also mean for files that legitimately have no extension like As for any specific examples like |
// session storage. Where the next time the editor is opened it's info is gone | ||
this.promptedForExt = []; | ||
|
||
atom.grammars.emitter.on("did-auto-assign-grammar", async (data) => { |
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 relates to my comment: #907 (comment)
Basically, we usually have an API like onDid...
to add callbacks. I think it's a good idea to add one to the other PR, and use it here.
In any way - we should never add a callback without a cleanup, so we might want to add a CompositeDisposable
here and dispose it when deactivating package
return; | ||
} | ||
|
||
const packages = await this.checkForGrammars(ext); |
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 don't think you can use await
here, right? We need activate
to be async, or move this to a different method...
atom.commands.add("atom-workspace", { | ||
"grammar-finder:find-grammars-for-file": async () => { | ||
// Here we can let users find a grammar for the current file, even if | ||
// it's already correctly identified | ||
const grammar = atom.workspace.getActiveTextEditor().getGrammar(); | ||
const buffer = atom.workspace.getActiveTextEditor().buffer; | ||
|
||
let extOrFalse = this.inspectAssignment( | ||
{ | ||
grammar: grammar, | ||
buffer: buffer | ||
}, | ||
{ | ||
ignoreScope: true | ||
} | ||
); | ||
|
||
if (!extOrFalse) { | ||
// We didn't find any grammar, since this is manually invoked we may want to alert | ||
atom.notifications.addInfo("Grammar-Finder was unable to identify the file.", { dismissable: true }); | ||
return; | ||
} | ||
|
||
let ext = extOrFalse.replace(".", ""); | ||
|
||
const ignoreExtList = atom.config.get("grammar-finder.ignoreExtList"); | ||
|
||
if (ignoreExtList.includes(ext)) { | ||
// we have been told to ignore this ext, since manually invoked we may want to alert | ||
atom.notifications.addInfo("This file is present on Grammar-Finder's ignore list.", { dismissable: true }); | ||
return; | ||
} | ||
|
||
const packages = await this.checkForGrammars(ext); | ||
|
||
if (packages.length === 0) { | ||
// No packages were found that support this grammar | ||
// since manuall invoked we may want to notify | ||
atom.notifications.addInfo(`Unable to locate any Grammars for '${ext}'.`, { dismissable: true }); | ||
return; | ||
} | ||
|
||
// Lets notify the user about the found packages | ||
this.notify(packages, ext, `'${packages.length}' Installable Grammars are available for '${ext}'.`); | ||
} |
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.
Can we move all of this to a method, so it's easier to read?
} | ||
|
||
inspectAssignment(data, opts = {}) { | ||
console.log(`grammar-finder.inspectAssignment(${data.grammar.scopeName}, ${data.buffer.getPath()})`); |
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.
Can we only log on dev mode? Seems like a "debug info" here.
ext = parsed.name; | ||
} | ||
|
||
console.log(`File: ${filePath} - Ext: ${ext}`); |
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.
Same here about a dev/debug mode
} | ||
|
||
async checkForGrammars(ext) { | ||
this.superagent ??= require("superagent"); |
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.
What is superagent?
|
||
@package-card-background-color: lighten(@tool-panel-background-color, 8%); | ||
|
||
.list-group .package-card.selected::before { |
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.
Because of the way CSS works on Pulsar, it's always a good idea to make the "core" selector the same as the package name. So, instead of .package-card
, use something like .grammar-finder
, or even grammar-finder.package-card
, WDYT?
Requires #907
This Draft PR adds a new core package
grammar-finder
to Pulsar.The decision to add this package is still under review, and until such time as it's agreed on, this PR will remain in draft status.
Grammar-Finder is a package that takes advantage of the new backend feature that allows searching of packages via the file extension that the grammar within the package supports.
This package comes with two ways to discover these packages:
grammar-finder:find-grammars-for-file
which will grab the extension of the current open file and search for any packages on the PPR that support said extension.AutoFind
this feature is really the selling point of the package. It uses the new event introduced in [core] Emit an Event whenever a Grammar is AutoAssigned #907 and if Pulsar is unable to find a suitable grammar for a file, opening the default Null Grammar, it'll automatically search for a community package that supports this file extension and create a notification for the user to view the list.In implementing this package I tried to put as much room as possible for removing interactions the user doesn't want. Such as being able to use the command palette even if
AutoFind
is disabled to find a suitable package.Additionally, this package has a config that allows an array of file extensions that can be added , which it will ignore for any and all checks and never prompt for installable packages.