Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Commit c5c166c

Browse files
committed
WIP.
1 parent cf26fb8 commit c5c166c

File tree

3 files changed

+260
-371
lines changed

3 files changed

+260
-371
lines changed

src/common/cancellation.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
import { CancellationToken, CancellationTokenSource } from 'vscode-jsonrpc'
2+
import { createAbortError } from '@sourcegraph/basic-code-intel'
23

3-
export interface AbortError extends Error {
4-
name: 'AbortError'
5-
}
6-
7-
/**
8-
* Creates an Error with name "AbortError"
9-
*/
10-
export const createAbortError = (): AbortError => Object.assign(new Error('Aborted'), { name: 'AbortError' as const })
11-
12-
/**
13-
* Returns true if the given value is an AbortError
14-
*/
15-
export const isAbortError = (err: any): err is AbortError =>
16-
typeof err === 'object' && err !== null && err.name === 'AbortError'
17-
18-
export function throwIfAbortError(err: unknown): void {
19-
if (isAbortError(err)) {
20-
throw err
21-
}
22-
}
4+
export { AbortError, createAbortError, isAbortError, throwIfAbortError } from '@sourcegraph/basic-code-intel'
235

246
/**
257
* Throws an AbortError if the given AbortSignal is already aborted

src/extension/basic-code-intel.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
import { Handler, Providers } from '@sourcegraph/basic-code-intel'
1+
import { HandlerArgs } from '@sourcegraph/basic-code-intel'
22
import * as path from 'path'
33
import * as sourcegraph from 'sourcegraph'
44

5-
export function initBasicCodeIntel(): Providers {
6-
return new Handler({
7-
sourcegraph,
8-
languageID: 'typescript',
9-
fileExts: ['ts', 'tsx', 'js', 'jsx'],
10-
commentStyle: {
11-
lineRegex: /\/\/\s?/,
12-
block: {
13-
startRegex: /\/\*\*?/,
14-
lineNoiseRegex: /(^\s*\*\s?)?/,
15-
endRegex: /\*\//,
16-
},
5+
export const handlerArgs: HandlerArgs = {
6+
sourcegraph,
7+
languageID: 'typescript',
8+
fileExts: ['ts', 'tsx', 'js', 'jsx'],
9+
commentStyle: {
10+
lineRegex: /\/\/\s?/,
11+
block: {
12+
startRegex: /\/\*\*?/,
13+
lineNoiseRegex: /(^\s*\*\s?)?/,
14+
endRegex: /\*\//,
1715
},
18-
filterDefinitions: ({ filePath, fileContent, results }) => {
19-
const imports = fileContent
20-
.split('\n')
21-
.map(line => {
22-
// Matches the import at index 1
23-
const match = /\bfrom ['"](.*)['"];?$/.exec(line) || /\brequire\(['"](.*)['"]\)/.exec(line)
24-
return match ? match[1] : undefined
25-
})
26-
.filter((x): x is string => Boolean(x))
16+
},
17+
filterDefinitions: ({ filePath, fileContent, results }) => {
18+
const imports = fileContent
19+
.split('\n')
20+
.map(line => {
21+
// Matches the import at index 1
22+
const match = /\bfrom ['"](.*)['"];?$/.exec(line) || /\brequire\(['"](.*)['"]\)/.exec(line)
23+
return match ? match[1] : undefined
24+
})
25+
.filter((x): x is string => Boolean(x))
2726

28-
const filteredResults = results.filter(result =>
29-
imports.some(i => path.join(path.dirname(filePath), i) === result.file.replace(/\.[^/.]+$/, ''))
30-
)
27+
const filteredResults = results.filter(result =>
28+
imports.some(i => path.join(path.dirname(filePath), i) === result.file.replace(/\.[^/.]+$/, ''))
29+
)
3130

32-
return filteredResults.length === 0 ? results : filteredResults
33-
},
34-
})
31+
return filteredResults.length === 0 ? results : filteredResults
32+
},
3533
}

0 commit comments

Comments
 (0)