Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@atlassianlabs/jql-autocomplete
Advanced tools
This package allows consumers to retrieve autocomplete suggestions for a given JQL query. JQL
Autocomplete leverages the antlr4-c3 library to provide
code completion candidates using the ANTLR4 generated @atlassianlabs/jql-parser
. Refer to
antlr4-c3 for a more in-depth introduction into code
completion with ANTLR4 grammars.
For a simple use case you'll want to construct a new JQLAutocomplete
object for a given source
query.
import { JQLAutocomplete } from '@atlassianlabs/jql-autocomplete';
const autocomplete = JQLAutocomplete.fromText("assignee = currentUser()");
You can then specify the (zero-indexed) caret position to retrieve suggestions for, e.g.:
// Caret positioned at "assignee = "
const selectionStart = 11;
const selectionStop = 11;
const suggestions = autocomplete.getJQLSuggestionsForCaretPosition([
selectionStart,
selectionStop,
]);
console.log(suggestions);
Will output the following response:
{
"tokens": {
"matchedText": "",
"replacePosition": [11,11],
"values": ["EMPTY"]
},
"rules": {
"function": {
"matchedText": "",
"replacePosition": [11,11],
"context": {
"field": "assignee",
"operator": "="
}
},
"value": {
"matchedText": "",
"replacePosition": [11,11],
"context": {
"field": "assignee",
"operator": "="
}
}
}
}
This includes a collection of tokens and rules that are valid for the given caret position. Rules are essential for deriving more than just keywords from your autocomplete.
As you can see in the above example a valid query could be produced using:
EMPTY
token, e.g. assignee = EMPTY
function
rule, e.g. assignee = currentUser()
value
rule, e.g. assignee = xxxxxxxxx
Typically, when encountering rules you'll want to enrich this information with Jira data. To do so you can leverage Jira Cloud REST API's.
yarn add @atlassianlabs/jql-autocomplete
When constructing an autocomplete object you can specify a collection of ignoredTokens
and
preferredRules
. When not provided, the autocomplete engine specified default arguments which are
suitable for most autocomplete use cases. You can read more about these options in the
antlr4-c3 documentation.
We also extend the antlr4-c3
configuration options with a new argument, delimiterTokens
. By
default JQLAutocomplete
will provide suggestions for the token immediately preceding the caret.
When the caret is positioned at a delimiter token then we'll look for suggestions after the
current token.
For example:
import { JQLLexer, JQLParser } from '@atlassianlabs/jql-parser';
import { JQLAutocomplete } from '@atlassianlabs/jql-autocomplete';
const ignoredTokens = new Set([JQLLexer.NOT_EQUALS]); // Exclude != tokens from suggestions
const preferredRules = new Set([JQLParser.RULE_jqlField]) // Only show rule suggestions for fields
const delimiterTokens = new Set([JQLLexer.COMMA]) // Give suggestions for tokens AFTER commas
const autocomplete = JQLAutocomplete.fromText("assignee = currentUser()", ignoredTokens, preferredRules, delimiterTokens);
For developers outside of Atlassian looking for help, or to report issues, please make a post on the community forum. We will monitor the forums and redirect topics to the appropriate maintainers.
Copyright (c) 2021 - 2022 Atlassian and others. Apache 2.0 licensed, see LICENSE file.
FAQs
JQL autocomplete engine
The npm package @atlassianlabs/jql-autocomplete receives a total of 1,547 weekly downloads. As such, @atlassianlabs/jql-autocomplete popularity was classified as popular.
We found that @atlassianlabs/jql-autocomplete demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.