diff --git a/package.json b/package.json index 3680abe..076428f 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "typescript": "^3.1.6" }, "dependencies": { - "@sourcegraph/basic-code-intel": "6.0.7", + "@sourcegraph/basic-code-intel": "6.0.9", "@sourcegraph/vscode-ws-jsonrpc": "0.0.3-fork", "prettier": "^1.16.4", "rxjs": "^6.3.3", diff --git a/src/lang-go.ts b/src/lang-go.ts index 45811f0..ca7306c 100644 --- a/src/lang-go.ts +++ b/src/lang-go.ts @@ -699,7 +699,35 @@ export function activate(ctx: sourcegraph.ExtensionContext = DUMMY_CTX): void { activateBasicCodeIntel({ languageID: 'go', fileExts: ['go'], - definitionPatterns: ['\\b%s(,\\s\\w+)*\\s\\:=', '(var|const)\\s%s\\s'], + filterDefinitions: ({ doc, pos, fileContent, results }) => { + const currentFileImportedPaths = fileContent + .split('\n') + .map(line => { + // Matches the import at index 3 + const match = /^(import |\t)(\w+ |\. )?"(.*)"$/.exec(line) + return match ? match[3] : undefined + }) + .filter((x): x is string => Boolean(x)) + + function dir(path: string): string { + return path.slice(0, path.lastIndexOf('/')) + } + + const currentFileURL = new URL(doc.uri) + const currentRepository = currentFileURL.hostname + currentFileURL.pathname + const currentFilePath = currentFileURL.hash.slice(1) + const currentFileImportPath = currentRepository + '/' + dir(currentFilePath) + + const filteredResults = results.filter(result => { + const resultImportPath = result.repo + '/' + dir(result.file) + return ( + currentFileImportedPaths.some(i => resultImportPath.includes(i)) || + resultImportPath === currentFileImportPath + ) + }) + + return filteredResults.length === 0 ? results : filteredResults + }, commentStyle: { lineRegex: /\/\/\s?/, }, diff --git a/yarn.lock b/yarn.lock index e1c0eb4..59ef46b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -700,14 +700,15 @@ resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" integrity sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow== -"@sourcegraph/basic-code-intel@6.0.7": - version "6.0.7" - resolved "https://registry.yarnpkg.com/@sourcegraph/basic-code-intel/-/basic-code-intel-6.0.7.tgz#6ba8623c1c5e71f780a059ccea2120ffdc1e3600" - integrity sha512-+amGIq54N3aVOj7AxNtW6QtDfUVvtT253Ha+i9sofyo217L/7Ucwo/WoDGuded9Ng9FUxUM6UOS3MREW+lkUGQ== +"@sourcegraph/basic-code-intel@6.0.9": + version "6.0.9" + resolved "https://registry.yarnpkg.com/@sourcegraph/basic-code-intel/-/basic-code-intel-6.0.9.tgz#7c76513a5cda622e86e966a5dd4128be677278bc" + integrity sha512-/pfZ1E8mhetl3wOVAD3nn8DfQoQHE+PzvezzPXF3P+sSZyn7p4oHErn+ezo4gR3d7UwjZ4UEn0UkbSdW5RWjnw== dependencies: lodash "^4.17.11" rxjs "^6.3.3" sourcegraph "^23.0.0" + sprintf-js "^1.1.2" "@sourcegraph/prettierrc@^2.2.0": version "2.2.0" @@ -5155,6 +5156,11 @@ split-string@^3.0.1, split-string@^3.0.2: dependencies: extend-shallow "^3.0.0" +sprintf-js@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673" + integrity sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug== + sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"