-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Tree-sitter rolling fixes, 1.120 edition #1062
Changes from 7 commits
358cb02
ce6989e
8090558
af133b0
3b25873
4388bce
11e2f75
6846b9c
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 |
---|---|---|
|
@@ -841,6 +841,9 @@ | |
"new" @keyword.operator.new._LANG_ | ||
|
||
"=" @keyword.operator.assignment._LANG_ | ||
|
||
["&" "|" "<<" ">>" ">>>" "~" "^"] @keyword.operator.bitwise.js | ||
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. (re: af133b0) Was going to ask if we should include bitwise assignment operators somehow, but I see they are already there later in the file... I guess that's the part we did already. Heh. Well, good to get these as well! (For reference, if we want to check if we've got all of these, though I'm not requesting that as a reviewer for the present PR. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) |
||
|
||
(non_null_expression "!" @keyword.operator.non-null._LANG_) | ||
(unary_expression "!" @keyword.operator.unary._LANG_) | ||
|
||
|
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. (re 11e2f75)
Sounds reasonable to me! |
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. (re 4388bce) Specs are appreciated! 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,7 @@ module.exports = class WASMTreeSitterGrammar { | |
}).then(() => { | ||
this._queryFilesLoaded = true; | ||
this._loadQueryFilesPromise = null; | ||
this.emitter.emit('did-load-query-files', this); | ||
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 pre-emptively explain this so that it's here when someone (historically @DeeDeeG) looks over it. A feature was requested that would require a new indentation query. I wanted to give the user a workaround that they could drop into their init file, but found it surprisingly hard to pull it off. The goal of the code in that comment is to take the content that's already in the indentation query, add an extra statement, then set that as the new indentation query for the grammar… and have it apply to all editors without having to close and open a given file again. But:
Hence this fix:
This is still a sloppy way to customize one's Tree-sitter queries, and there's further room for improvement in the future; but this improves the status quo. 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. (re: 3b25873) Asking mostly because it's a bit arcane to me: Is this implementation risking being over-complicated? If you envision some hypothetical world where a more green-field design were possible, is this how you'd want it to be done? If not, is the limitation causing it to be done this way handed to us by Tree-sitter, or Atom/Pulsar stuff? Or is this sort of a convenient way to implement? And... any foreseen issues with this approach? (Not sure why I'm asking all these questions, just trying to pick your brain a bit I guess. Good to know if you've considered it well before we merge it. Seems from the fact you chose to write it up preemptively that you probably have considered it. But anyway, bustin' chops today.) 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 so? Some of the arcana about how query files are loaded could maybe be simplified, but the basic way queries work — one query file for syntax highlighting, one for indentation, one for folding… — is broadly how Neovim does things, and probably other editors. By comparison: if you wanted to customize how a TextMate grammar did…
I can't tell which aspect of the system you're asking about, but I can explain further if you have follow-up questions. |
||
}); | ||
|
||
return this._loadQueryFilesPromise; | ||
|
@@ -324,7 +325,7 @@ module.exports = class WASMTreeSitterGrammar { | |
this.queryCache.delete(queryType); | ||
this[queryType] = contents; | ||
let query = await this.getQuery(queryType); | ||
this.emitter.emit('did-change-query-file', { filePath: '', queryType }); | ||
this.emitter.emit('did-change-query', { filePath: '', queryType }); | ||
return query; | ||
} | ||
|
||
|
@@ -350,29 +351,49 @@ module.exports = class WASMTreeSitterGrammar { | |
this.queryCache.delete(queryType); | ||
return; | ||
} | ||
this.emitter.emit('did-change-query-file', { filePath, queryType }); | ||
this.emitter.emit('did-change-query', { filePath, queryType }); | ||
}); | ||
})); | ||
} | ||
} | ||
|
||
// Extended: Calls `callback` when any of this grammar's query files change. | ||
// Extended: Calls `callback` when any of this grammar's queries change. | ||
// | ||
// Since a grammar’s query files won’t change during ordinary operation, this | ||
// method’s main purpose is to aid the development of grammars by applying | ||
// changes to query files in real time. This happens automatically when | ||
// Pulsar is running in dev mode. | ||
// A grammar's queries typically will not change after initial load. When | ||
// they do, it may mean: | ||
// | ||
// The callback is invoked with an object argument with two keys: | ||
// - The user is editing query files in dev mode; Pulsar will automatically | ||
// reload queries in dev mode after changes. | ||
// - A community package is altering a query file via an API like | ||
// {::setQueryForTest}. | ||
// | ||
// * `callback`: The callback to be invoked. Takes one argument: | ||
// * `data`: An object with keys: | ||
// * `filePath`: The path to the query file on disk. | ||
// * `queryType`: The type of query file, as denoted by its | ||
// * `callback` {Function} | ||
// * `data` {Object} | ||
// * `filePath` {String} The path to the query file on disk. | ||
// * `queryType` {String} The type of query file, as denoted by its | ||
// configuration key in the grammar file. Usually one of | ||
// `highlightsQuery`, `indentsQuery`, `foldsQuery`, or `tagsQuery`. | ||
onDidChangeQuery(callback) { | ||
return this.emitter.on('did-change-query', callback); | ||
} | ||
|
||
// Extended: Calls `callback` when any of this grammar's queries change. | ||
// | ||
// Alias of {::onDidChangeQuery}. | ||
onDidChangeQueryFile(callback) { | ||
return this.emitter.on('did-change-query-file', callback); | ||
return this.onDidChangeQuery(callback); | ||
} | ||
|
||
// Extended: Calls `callback` when this grammar first loads its query files. | ||
// | ||
// Since a grammar may not load immedately on startup, this method makes it | ||
// easier to hook into the query life cycle in order to modify or augment a | ||
// grammar's default queries. | ||
// | ||
// * callback A function with the following argument: | ||
// * grammar The {WASMTreeSitterGrammar} whose queries have loaded. | ||
onDidLoadQueryFiles(callback) { | ||
return this.emitter.on('did-load-query-files', callback); | ||
} | ||
|
||
activate() { | ||
|
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.
👍 (re: 8090558)