@atlassianlabs/jql-autocomplete

中文文档
1.1.1发布于 2023/07/12TypeScriptESM + CJS近 30 天下载 5146

JQL autocomplete engine

原始使用文档
文档目录6 节
  1. Usage
  2. Installation
  3. Documentation
  4. Fine tuning
  5. Support
  6. License

JQL Autocomplete

Atlassian license

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.

Usage

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:

  • An EMPTY token, e.g. assignee = EMPTY
  • A function rule, e.g. assignee = currentUser()
  • A 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.

Installation

yarn add @atlassianlabs/jql-autocomplete

Documentation

Fine tuning

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);

Support

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.

License

Copyright (c) 2021 - 2022 Atlassian and others. Apache 2.0 licensed, see LICENSE file.

版本与发布记录

@atlassianlabs/jql-autocomplete 共发布 5 个版本,首次发布于 2021/12/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.1latest2023/07/123 年前
1.1.02023/06/023 年前
1.0.12022/09/264 年前
1.0.02022/02/214 年前
0.0.12021/12/104 年前

关于 @atlassianlabs/jql-autocomplete 的常见问题

@atlassianlabs/jql-autocomplete 是什么?

JQL autocomplete engine

如何安装 @atlassianlabs/jql-autocomplete?

在项目目录运行 npm install @atlassianlabs/jql-autocomplete,或使用 pnpm add / yarn add / bun add。

@atlassianlabs/jql-autocomplete 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atlassianlabs/jql-autocomplete 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@atlassianlabs/jql-autocomplete 可以商用吗?

@atlassianlabs/jql-autocomplete 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@atlassianlabs/jql-autocomplete 的下载量有多少?

根据 npm 官方下载统计,@atlassianlabs/jql-autocomplete 在 2026/10/07 – 2026/11/05 这 30 天内被下载 5,146 次,日均约 172 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atlassianlabs/jql-autocomplete 还在维护吗?

最新版本 1.1.1 发布于 2023/07/12(3 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/12/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。