linear-ls 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/linear.js +115 -0
- package/dist/server.js +106 -84
- package/dist/test.js +45 -0
- package/dist/types.generated.js +2 -0
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
1
|
# lls
|
|
2
|
+
|
|
2
3
|
Linear Language Server
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm i -g linear-ls
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
### Hover on Issues
|
|
14
|
+
|
|
15
|
+
Hovering on ticket identifier shows the ticket description.
|
|
16
|
+
|
|
17
|
+
<img width="800" alt="image" src="https://user-images.githubusercontent.com/609452/218294991-ef0dfe07-832d-418b-9e7e-8b630f4c2c49.png">
|
|
18
|
+
|
|
19
|
+
### Issue Completion
|
|
20
|
+
|
|
21
|
+
Typing team key, hyphen and search term (e.g. `EUC-thing`) triggers issue search. Selecting a result puts in a link to your issue.
|
|
22
|
+
|
|
23
|
+
<img width="800" alt="image" src="https://user-images.githubusercontent.com/609452/218295062-4a0bbd6c-bb92-44c6-9301-4ab7b1522978.png">
|
|
24
|
+
|
|
25
|
+
### Create Ticket from Text Selection
|
|
26
|
+
|
|
27
|
+
TODO
|
package/dist/linear.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findIssuesByTitle = exports.getIssueByKey = exports.getTeamKeys = void 0;
|
|
7
|
+
const core_1 = require("@urql/core");
|
|
8
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
+
const client = (0, core_1.createClient)({
|
|
10
|
+
url: "https://api.linear.app/graphql",
|
|
11
|
+
requestPolicy: "cache-first",
|
|
12
|
+
exchanges: core_1.defaultExchanges,
|
|
13
|
+
fetch: node_fetch_1.default,
|
|
14
|
+
fetchOptions: {
|
|
15
|
+
headers: {
|
|
16
|
+
authorization: process.env.LINEAR_API_KEY,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
async function getTeamKeys() {
|
|
21
|
+
const resp = await client
|
|
22
|
+
.query((0, core_1.gql) `
|
|
23
|
+
query FindTeamPrefixes {
|
|
24
|
+
teams {
|
|
25
|
+
nodes {
|
|
26
|
+
id
|
|
27
|
+
key
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`, {})
|
|
32
|
+
.toPromise();
|
|
33
|
+
return resp.data?.teams.nodes.map((t) => t.key) ?? [];
|
|
34
|
+
}
|
|
35
|
+
exports.getTeamKeys = getTeamKeys;
|
|
36
|
+
const issueFragment = (0, core_1.gql) `
|
|
37
|
+
fragment Issue on Issue {
|
|
38
|
+
id
|
|
39
|
+
identifier
|
|
40
|
+
title
|
|
41
|
+
description
|
|
42
|
+
url
|
|
43
|
+
team {
|
|
44
|
+
id
|
|
45
|
+
key
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
async function getIssueByKey(key) {
|
|
50
|
+
const components = key.split("-");
|
|
51
|
+
const teamKey = components[0];
|
|
52
|
+
if (teamKey?.length !== 3) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const issueNumber = Number(components[1]);
|
|
56
|
+
if (!Number.isInteger(issueNumber)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const resp = await client
|
|
60
|
+
.query((0, core_1.gql) `
|
|
61
|
+
query GetIssueByKey($filter: IssueFilter!) {
|
|
62
|
+
issues(filter: $filter) {
|
|
63
|
+
nodes {
|
|
64
|
+
...Issue
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
${issueFragment}
|
|
69
|
+
`, {
|
|
70
|
+
filter: {
|
|
71
|
+
team: { key: { eqIgnoreCase: teamKey } },
|
|
72
|
+
number: { eq: issueNumber },
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
.toPromise();
|
|
76
|
+
return resp.data?.issues?.nodes[0];
|
|
77
|
+
}
|
|
78
|
+
exports.getIssueByKey = getIssueByKey;
|
|
79
|
+
async function findIssuesByTitle(teamKeys, issueTitle) {
|
|
80
|
+
const resp = await client
|
|
81
|
+
.query((0, core_1.gql) `
|
|
82
|
+
query FindIssuesByTitle(
|
|
83
|
+
$teamFilter: TeamFilter!
|
|
84
|
+
$issueFilter: IssueFilter!
|
|
85
|
+
) {
|
|
86
|
+
teams(filter: $teamFilter) {
|
|
87
|
+
nodes {
|
|
88
|
+
id
|
|
89
|
+
issues(filter: $issueFilter) {
|
|
90
|
+
nodes {
|
|
91
|
+
...Issue
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
${issueFragment}
|
|
98
|
+
`, {
|
|
99
|
+
teamFilter: {
|
|
100
|
+
or: teamKeys.map((tk) => ({
|
|
101
|
+
key: {
|
|
102
|
+
containsIgnoreCase: tk,
|
|
103
|
+
},
|
|
104
|
+
})),
|
|
105
|
+
},
|
|
106
|
+
issueFilter: {
|
|
107
|
+
title: {
|
|
108
|
+
containsIgnoreCase: issueTitle,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
.toPromise();
|
|
113
|
+
return resp.data?.teams.nodes.flatMap((team) => team.issues.nodes);
|
|
114
|
+
}
|
|
115
|
+
exports.findIssuesByTitle = findIssuesByTitle;
|
package/dist/server.js
CHANGED
|
@@ -2,109 +2,131 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_1 = require("vscode-languageserver/node");
|
|
4
4
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
5
|
-
const
|
|
6
|
-
let globalSettings = defaultSettings;
|
|
5
|
+
const linear_1 = require("./linear");
|
|
7
6
|
const connection = (0, node_1.createConnection)(node_1.ProposedFeatures.all);
|
|
8
7
|
const documents = new node_1.TextDocuments(vscode_languageserver_textdocument_1.TextDocument);
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const teamKeys = new Set();
|
|
9
|
+
const issues = new Map();
|
|
10
|
+
const issuePositions = new Map();
|
|
11
|
+
// [MOB-201](https://linear.app/eucalyptus/issue/MOB-201/devices-screen-not-paired-state)
|
|
12
|
+
connection.onInitialize(async () => {
|
|
13
|
+
await (0, linear_1.getTeamKeys)().then((keys) => {
|
|
14
|
+
keys.map((k) => {
|
|
15
|
+
teamKeys.add(k);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
17
18
|
const result = {
|
|
18
19
|
capabilities: {
|
|
19
20
|
textDocumentSync: node_1.TextDocumentSyncKind.Incremental,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
21
|
+
codeActionProvider: {},
|
|
22
|
+
hoverProvider: {},
|
|
23
|
+
completionProvider: { resolveProvider: true },
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
|
-
if (supportsWorkspaceFolder) {
|
|
26
|
-
result.capabilities.workspace = {
|
|
27
|
-
workspaceFolders: {
|
|
28
|
-
supported: true,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
26
|
return result;
|
|
33
27
|
});
|
|
34
|
-
connection.
|
|
35
|
-
if (
|
|
36
|
-
|
|
28
|
+
connection.onCodeAction((params) => {
|
|
29
|
+
if (params.context.triggerKind === node_1.CodeActionTriggerKind.Invoked) {
|
|
30
|
+
const textDocument = documents.get(params.textDocument.uri);
|
|
31
|
+
if (!textDocument) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const text = textDocument.getText(params.range);
|
|
35
|
+
if (!text) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// TODO: Implement command to create ticket
|
|
39
|
+
return [{ title: "Create Ticket" }];
|
|
37
40
|
}
|
|
38
41
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
documents.onDidChangeContent((change) => {
|
|
43
|
+
const text = change.document.getText();
|
|
44
|
+
const documentPositions = [];
|
|
45
|
+
Array.from(teamKeys)
|
|
46
|
+
.flatMap((prefix) => {
|
|
47
|
+
return Array.from(text.matchAll(new RegExp(`${prefix}-[0-9]*`, "g")));
|
|
48
|
+
})
|
|
49
|
+
.forEach((m) => {
|
|
50
|
+
const issueKey = m[0];
|
|
51
|
+
const positionStart = change.document.positionAt(m.index ?? 0);
|
|
52
|
+
const positionEnd = change.document.positionAt(issueKey.length + (m.index ?? 0));
|
|
53
|
+
// Write down that we've seen the issue, but don't
|
|
54
|
+
// fetch the definition just yet.
|
|
55
|
+
if (!issues.has(issueKey)) {
|
|
56
|
+
issues.set(issueKey, undefined);
|
|
57
|
+
}
|
|
58
|
+
documentPositions.push({
|
|
59
|
+
issueKey,
|
|
60
|
+
positionStart,
|
|
61
|
+
positionEnd,
|
|
62
|
+
offsetStart: change.document.offsetAt(positionStart),
|
|
63
|
+
offsetEnd: change.document.offsetAt(positionEnd),
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
issuePositions.set(change.document.uri, documentPositions);
|
|
67
|
+
});
|
|
68
|
+
connection.onHover(async (params) => {
|
|
69
|
+
const documentPositions = issuePositions.get(params.textDocument.uri);
|
|
70
|
+
if (!documentPositions) {
|
|
71
|
+
return;
|
|
42
72
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
const textDocument = documents.get(params.textDocument.uri);
|
|
74
|
+
if (!textDocument) {
|
|
75
|
+
return;
|
|
46
76
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return Promise.resolve(globalSettings);
|
|
77
|
+
const cursorOffset = textDocument.offsetAt(params.position);
|
|
78
|
+
const targetIssue = documentPositions.find((dp) => dp.offsetStart <= cursorOffset && dp.offsetEnd > cursorOffset);
|
|
79
|
+
if (!targetIssue) {
|
|
80
|
+
return;
|
|
52
81
|
}
|
|
53
|
-
|
|
54
|
-
if (!
|
|
55
|
-
|
|
56
|
-
scopeUri: resource,
|
|
57
|
-
section: "lls",
|
|
58
|
-
});
|
|
59
|
-
documentSettings.set(resource, result);
|
|
82
|
+
const issue = await (0, linear_1.getIssueByKey)(targetIssue.issueKey);
|
|
83
|
+
if (!issue) {
|
|
84
|
+
return;
|
|
60
85
|
}
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
documentSettings.delete(e.document.uri);
|
|
65
|
-
});
|
|
66
|
-
documents.onDidChangeContent((change) => {
|
|
67
|
-
identifyTickets(change.document);
|
|
86
|
+
return {
|
|
87
|
+
contents: issue.description ?? "Not available",
|
|
88
|
+
};
|
|
68
89
|
});
|
|
69
|
-
async
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return;
|
|
90
|
+
connection.onCompletion(async (params) => {
|
|
91
|
+
if (teamKeys.size === 0) {
|
|
92
|
+
return [];
|
|
73
93
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
severity: node_1.DiagnosticSeverity.Hint,
|
|
82
|
-
range: {
|
|
83
|
-
start: textDocument.positionAt(m.index ?? 0),
|
|
84
|
-
end: textDocument.positionAt((m.index ?? 0) + m[0].length),
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
});
|
|
94
|
+
const document = documents.get(params.textDocument.uri);
|
|
95
|
+
if (!document) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const lineToPosition = document?.getText({
|
|
99
|
+
start: { line: params.position.line, character: 0 },
|
|
100
|
+
end: { line: params.position.line, character: params.position.character },
|
|
88
101
|
});
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
connection.onCompletionResolve((item) => {
|
|
103
|
-
if (item.data === "MOB-1") {
|
|
104
|
-
item.detail = "Install the application";
|
|
105
|
-
item.documentation = "Details details";
|
|
102
|
+
const lastMatch = Array.from(teamKeys)
|
|
103
|
+
.flatMap((prefix) => Array.from(lineToPosition.matchAll(new RegExp(`(${prefix})-(.*)`, "g"))))
|
|
104
|
+
.at(-1);
|
|
105
|
+
if (!lastMatch) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const [, teamKey, searchString] = lastMatch;
|
|
109
|
+
if (!teamKey || !searchString) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const issues = await (0, linear_1.findIssuesByTitle)([teamKey], searchString);
|
|
113
|
+
if (issues === undefined) {
|
|
114
|
+
return [];
|
|
106
115
|
}
|
|
107
|
-
return
|
|
116
|
+
return issues.map((issue) => {
|
|
117
|
+
let label = `${issue.identifier}: ${issue.title}`;
|
|
118
|
+
if (label.length > 60) {
|
|
119
|
+
label = label.substring(0, 60) + "...";
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
data: issue,
|
|
123
|
+
detail: issue.description ?? "Not available",
|
|
124
|
+
insertText: `[${issue.identifier}](${issue.url})`,
|
|
125
|
+
filterText: `${issue.team.key}-${issue.title}`,
|
|
126
|
+
label,
|
|
127
|
+
kind: node_1.CompletionItemKind.Reference,
|
|
128
|
+
};
|
|
129
|
+
});
|
|
108
130
|
});
|
|
109
131
|
documents.listen(connection);
|
|
110
132
|
connection.listen();
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@urql/core");
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const client = (0, core_1.createClient)({
|
|
9
|
+
url: "https://api.linear.app/graphql",
|
|
10
|
+
exchanges: core_1.defaultExchanges,
|
|
11
|
+
fetch: node_fetch_1.default,
|
|
12
|
+
fetchOptions: {
|
|
13
|
+
headers: {
|
|
14
|
+
authorization: process.env.LINEAR_API_KEY,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
async function findIssues(teamKeys, issueTitle) {
|
|
19
|
+
const resp = await client
|
|
20
|
+
.query((0, core_1.gql) `
|
|
21
|
+
query FindIssues($teamFilter: TeamFilter!, $issueFilter: IssueFilter!) {
|
|
22
|
+
teams(filter: $teamFilter) {
|
|
23
|
+
nodes {
|
|
24
|
+
id
|
|
25
|
+
issues(filter: $issueFilter) {
|
|
26
|
+
nodes {
|
|
27
|
+
id
|
|
28
|
+
identifier
|
|
29
|
+
title
|
|
30
|
+
description
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`, {
|
|
37
|
+
teamFilter: {
|
|
38
|
+
or: teamKeys.map((tk) => [{ key: { containsIgnoreCase: tk } }]),
|
|
39
|
+
},
|
|
40
|
+
issueFilter: issueTitle,
|
|
41
|
+
})
|
|
42
|
+
.toPromise();
|
|
43
|
+
console.log(JSON.stringify(resp, null, 2));
|
|
44
|
+
}
|
|
45
|
+
findIssues(["MOB"], "RUM");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linear-ls",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Linear Language Server",
|
|
5
5
|
"bin": "index.js",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,10 +12,17 @@
|
|
|
12
12
|
"index.js"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@urql/core": "^3.1.1",
|
|
16
|
+
"graphql": "^16.6.0",
|
|
17
|
+
"node-fetch": "^2.6.7",
|
|
15
18
|
"vscode-languageserver": "^8.0.2",
|
|
16
19
|
"vscode-languageserver-textdocument": "^1.0.8"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
22
|
+
"@graphql-codegen/cli": "^3.0.0",
|
|
23
|
+
"@graphql-codegen/typescript": "^3.0.0",
|
|
24
|
+
"@graphql-codegen/typescript-operations": "^3.0.0",
|
|
25
|
+
"@types/node-fetch": "^2.6.2",
|
|
19
26
|
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
20
27
|
"@typescript-eslint/parser": "^5.50.0",
|
|
21
28
|
"eslint": "^8.33.0",
|
|
@@ -34,7 +41,6 @@
|
|
|
34
41
|
"rules": {
|
|
35
42
|
"@typescript-eslint/no-unused-vars": "error",
|
|
36
43
|
"@typescript-eslint/no-explicit-any": "error",
|
|
37
|
-
"@typescript-eslint/explicit-module-boundary-types": "error",
|
|
38
44
|
"@typescript-eslint/no-non-null-assertion": "error"
|
|
39
45
|
}
|
|
40
46
|
}
|