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

Commit 2289874

Browse files
committed
WIP.
1 parent cf26fb8 commit 2289874

File tree

3 files changed

+295
-477
lines changed

3 files changed

+295
-477
lines changed

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/src/index'
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)