This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathjava.ts
More file actions
39 lines (34 loc) · 1.43 KB
/
java.ts
File metadata and controls
39 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as path from 'path'
import { javaStyleComment } from './comments'
import { FilterContext, LanguageSpec, Result, LSIFSupport } from './spec'
import { extractFromLines, filterResultsByImports, slashToDot } from './util'
/**
* Filter a list of candidate definitions to select those likely to be valid
* cross-references for a definition in this file. Accept candidates located
* in the same package or in a directory that includes one of the imported
* paths.
*
* If no candidates match, fall back to the raw (unfiltered) results so that
* the user doesn't get an empty response unless there really is nothing.
*/
function filterDefinitions<T extends Result>(results: T[], { fileContent }: FilterContext): T[] {
const importPaths = extractFromLines(
fileContent,
/^import ([\w.]+);$/,
/^import static ([\d._a-z]+)\.([\d_a-z]+|\*);$/
)
const currentPackage = extractFromLines(fileContent, /^package ([\w.]+);$/)
return filterResultsByImports(results, importPaths.concat(currentPackage), ({ file }, importPath) =>
// Match results with a dirname suffix of an import path
slashToDot(path.dirname(file)).endsWith(importPath)
)
}
export const javaSpec: LanguageSpec = {
languageID: 'java',
stylized: 'Java',
fileExts: ['java'],
commentStyles: [javaStyleComment],
textDocumentImplemenationSupport: true,
filterDefinitions,
lsifSupport: LSIFSupport.Experimental,
}