|
1 | | -import { Handler, Providers } from '@sourcegraph/basic-code-intel' |
| 1 | +import { HandlerArgs } from '@sourcegraph/basic-code-intel' |
2 | 2 | import * as path from 'path' |
3 | 3 | import * as sourcegraph from 'sourcegraph' |
4 | 4 |
|
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: /\*\//, |
17 | 15 | }, |
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)) |
27 | 26 |
|
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 | + ) |
31 | 30 |
|
32 | | - return filteredResults.length === 0 ? results : filteredResults |
33 | | - }, |
34 | | - }) |
| 31 | + return filteredResults.length === 0 ? results : filteredResults |
| 32 | + }, |
35 | 33 | } |
0 commit comments