From 09fa6f244171f0768dd6586f65a9f5294d6dd6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Thu, 29 Apr 2021 18:53:44 +0200 Subject: [PATCH] Add user setting to disable mixing LSIF/search-based results --- .vscode/settings.json | 1 + extensions/go/package.json | 4 + extensions/go/src/settings.ts | 116 ++++++++++---------- extensions/template/package.json | 4 + extensions/typescript/package.json | 4 + extensions/typescript/src/settings.ts | 152 +++++++++++++------------- shared/providers.ts | 3 + shared/search/settings.ts | 62 ++++++----- 8 files changed, 187 insertions(+), 159 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 79f7060d8..43511fab9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,5 @@ "**/coverage/": true, }, "typescript.tsdk": "node_modules/typescript/lib", + "editor.formatOnSave": true, } diff --git a/extensions/go/package.json b/extensions/go/package.json index 13efc7fcf..cf01694b6 100644 --- a/extensions/go/package.json +++ b/extensions/go/package.json @@ -88,6 +88,10 @@ "description": "Whether to fetch multiple precise definitions and references on hover.", "type": "boolean" }, + "codeIntel.disableMixedResults": { + "description": "If true, do not show 'search-based' results alongside LSIF results.", + "type": "boolean" + }, "basicCodeIntel.includeForks": { "description": "Whether to include forked repositories in search results.", "type": "boolean" diff --git a/extensions/go/src/settings.ts b/extensions/go/src/settings.ts index 69844cbb1..9642657d9 100644 --- a/extensions/go/src/settings.ts +++ b/extensions/go/src/settings.ts @@ -6,60 +6,64 @@ */ export interface Settings { - /** - * Whether to use pre-computed LSIF data for code intelligence (such as hovers, definitions, and references). See https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence. - */ - 'codeIntel.lsif'?: boolean - /** - * Whether to enable trace logging on the extension. - */ - 'codeIntel.traceExtension'?: boolean - /** - * Whether to fetch multiple precise definitions and references on hover. - */ - 'codeIntel.disableRangeQueries'?: boolean - /** - * Whether to include forked repositories in search results. - */ - 'basicCodeIntel.includeForks'?: boolean - /** - * Whether to include archived repositories in search results. - */ - 'basicCodeIntel.includeArchives'?: boolean - /** - * Whether to use only indexed requests to the search API. - */ - 'basicCodeIntel.indexOnly'?: boolean - /** - * The timeout (in milliseconds) for un-indexed search requests. - */ - 'basicCodeIntel.unindexedSearchTimeout'?: number - /** - * The address of the WebSocket language server to connect to (e.g. ws://host:4389). - */ - 'go.serverUrl'?: string - /** - * The address of the Sourcegraph instance from the perspective of the Go language server. - */ - 'go.sourcegraphUrl'?: string - /** - * The access token for the language server to use to fetch files from the Sourcegraph API. The extension will create this token and save it in your settings automatically. - */ - 'go.accessToken'?: string - /** - * Whether or not a second references provider for external references will be registered (defaults to false). - */ - 'go.showExternalReferences'?: boolean - /** - * The maximum number of repositories to look in when searching for external references for a symbol (defaults to 20). - */ - 'go.maxExternalReferenceRepos'?: number - /** - * The address to Go Doc Dot Org or a proxy that speaks the same API (only used on Sourcegraph.com). - */ - 'go.gddoURL'?: string - /** - * Address of a cors-anywhere service. This will cause the extension to send GDDO requests to this service instead of directly to api.godoc.org. For example: https://cors-anywhere.sourcegraph.com/https://api.godoc.org/importersgithub.com/sourcegraph/go-lsp. This would not be necessary if godoc.org set CORS headers. - */ - 'go.corsAnywhereURL'?: string + /** + * Whether to use pre-computed LSIF data for code intelligence (such as hovers, definitions, and references). See https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence. + */ + 'codeIntel.lsif'?: boolean + /** + * Whether to enable trace logging on the extension. + */ + 'codeIntel.traceExtension'?: boolean + /** + * Whether to fetch multiple precise definitions and references on hover. + */ + 'codeIntel.disableRangeQueries'?: boolean + /** + * If true, do not show 'search-based' results alongside LSIF results. + */ + 'codeIntel.disableMixedResults'?: boolean + /** + * Whether to include forked repositories in search results. + */ + 'basicCodeIntel.includeForks'?: boolean + /** + * Whether to include archived repositories in search results. + */ + 'basicCodeIntel.includeArchives'?: boolean + /** + * Whether to use only indexed requests to the search API. + */ + 'basicCodeIntel.indexOnly'?: boolean + /** + * The timeout (in milliseconds) for un-indexed search requests. + */ + 'basicCodeIntel.unindexedSearchTimeout'?: number + /** + * The address of the WebSocket language server to connect to (e.g. ws://host:4389). + */ + 'go.serverUrl'?: string + /** + * The address of the Sourcegraph instance from the perspective of the Go language server. + */ + 'go.sourcegraphUrl'?: string + /** + * The access token for the language server to use to fetch files from the Sourcegraph API. The extension will create this token and save it in your settings automatically. + */ + 'go.accessToken'?: string + /** + * Whether or not a second references provider for external references will be registered (defaults to false). + */ + 'go.showExternalReferences'?: boolean + /** + * The maximum number of repositories to look in when searching for external references for a symbol (defaults to 20). + */ + 'go.maxExternalReferenceRepos'?: number + /** + * The address to Go Doc Dot Org or a proxy that speaks the same API (only used on Sourcegraph.com). + */ + 'go.gddoURL'?: string + /** + * Address of a cors-anywhere service. This will cause the extension to send GDDO requests to this service instead of directly to api.godoc.org. For example: https://cors-anywhere.sourcegraph.com/https://api.godoc.org/importersgithub.com/sourcegraph/go-lsp. This would not be necessary if godoc.org set CORS headers. + */ + 'go.corsAnywhereURL'?: string } diff --git a/extensions/template/package.json b/extensions/template/package.json index 750d2ec59..a61c2e3c6 100644 --- a/extensions/template/package.json +++ b/extensions/template/package.json @@ -58,6 +58,10 @@ "description": "Whether to fetch multiple precise definitions and references on hover.", "type": "boolean" }, + "codeIntel.disableMixedResults": { + "description": "If true, do not show 'search-based' results alongside LSIF results.", + "type": "boolean" + }, "basicCodeIntel.includeForks": { "description": "Whether to include forked repositories in search results.", "type": "boolean" diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index 9e6036d1e..9c443dfdd 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -92,6 +92,10 @@ "description": "Whether to fetch multiple precise definitions and references on hover.", "type": "boolean" }, + "codeIntel.disableMixedResults": { + "description": "If true, do not show 'search-based' results alongside LSIF results.", + "type": "boolean" + }, "basicCodeIntel.includeForks": { "description": "Whether to include forked repositories in search results.", "type": "boolean" diff --git a/extensions/typescript/src/settings.ts b/extensions/typescript/src/settings.ts index 0a3065759..04ee1ea81 100644 --- a/extensions/typescript/src/settings.ts +++ b/extensions/typescript/src/settings.ts @@ -6,78 +6,82 @@ */ export interface Settings { - /** - * Whether to use pre-computed LSIF data for code intelligence (such as hovers, definitions, and references). See https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence. - */ - 'codeIntel.lsif'?: boolean - /** - * Whether to enable trace logging on the extension. - */ - 'codeIntel.traceExtension'?: boolean - /** - * Whether to fetch multiple precise definitions and references on hover. - */ - 'codeIntel.disableRangeQueries'?: boolean - /** - * Whether to include forked repositories in search results. - */ - 'basicCodeIntel.includeForks'?: boolean - /** - * Whether to include archived repositories in search results. - */ - 'basicCodeIntel.includeArchives'?: boolean - /** - * Whether to use only indexed requests to the search API. - */ - 'basicCodeIntel.indexOnly'?: boolean - /** - * The timeout (in milliseconds) for un-indexed search requests. - */ - 'basicCodeIntel.unindexedSearchTimeout'?: number - /** - * The address of the WebSocket language server to connect to (e.g. ws://host:8080). - */ - 'typescript.serverUrl'?: string - /** - * The address of the Sourcegraph instance from the perspective of the TypeScript language server. - */ - 'typescript.sourcegraphUrl'?: string - /** - * The access token for the language server to use to fetch files from the Sourcegraph API. The extension will create this token and save it in your settings automatically. - */ - 'typescript.accessToken'?: string - /** - * Whether or not a second references provider for external references will be registered (defaults to false). - */ - 'typescript.showExternalReferences'?: boolean - /** - * The maximum number of dependent packages to look in when searching for external references for a symbol (defaults to 20). - */ - 'typescript.maxExternalReferenceRepos'?: number - /** - * Whether to report progress while fetching sources, installing dependencies etc. (Default: true) - */ - 'typescript.progress'?: boolean - /** - * Whether to show compile errors on lines (Default: false) - */ - 'typescript.diagnostics.enable'?: boolean - /** - * Settings to be written into an npmrc in key/value format. Can be used to specify custom registries and tokens. - */ - 'typescript.npmrc'?: { - [k: string]: unknown - } - /** - * Whether to restart the language server after dependencies were installed (default true) - */ - 'typescript.restartAfterDependencyInstallation'?: boolean - /** - * The log level to pass to the TypeScript language server. Logs will be forwarded to the browser console with the prefix [langserver]. - */ - 'typescript.langserver.log'?: false | 'log' | 'info' | 'warn' | 'error' - /** - * The log level to pass to tsserver. Logs will be forwarded to the browser console with the prefix [tsserver]. - */ - 'typescript.tsserver.log'?: false | 'terse' | 'normal' | 'requestTime' | 'verbose' + /** + * Whether to use pre-computed LSIF data for code intelligence (such as hovers, definitions, and references). See https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence. + */ + 'codeIntel.lsif'?: boolean + /** + * Whether to enable trace logging on the extension. + */ + 'codeIntel.traceExtension'?: boolean + /** + * Whether to fetch multiple precise definitions and references on hover. + */ + 'codeIntel.disableRangeQueries'?: boolean + /** + * If true, do not show 'search-based' results alongside LSIF results. + */ + 'codeIntel.disableMixedResults'?: boolean + /** + * Whether to include forked repositories in search results. + */ + 'basicCodeIntel.includeForks'?: boolean + /** + * Whether to include archived repositories in search results. + */ + 'basicCodeIntel.includeArchives'?: boolean + /** + * Whether to use only indexed requests to the search API. + */ + 'basicCodeIntel.indexOnly'?: boolean + /** + * The timeout (in milliseconds) for un-indexed search requests. + */ + 'basicCodeIntel.unindexedSearchTimeout'?: number + /** + * The address of the WebSocket language server to connect to (e.g. ws://host:8080). + */ + 'typescript.serverUrl'?: string + /** + * The address of the Sourcegraph instance from the perspective of the TypeScript language server. + */ + 'typescript.sourcegraphUrl'?: string + /** + * The access token for the language server to use to fetch files from the Sourcegraph API. The extension will create this token and save it in your settings automatically. + */ + 'typescript.accessToken'?: string + /** + * Whether or not a second references provider for external references will be registered (defaults to false). + */ + 'typescript.showExternalReferences'?: boolean + /** + * The maximum number of dependent packages to look in when searching for external references for a symbol (defaults to 20). + */ + 'typescript.maxExternalReferenceRepos'?: number + /** + * Whether to report progress while fetching sources, installing dependencies etc. (Default: true) + */ + 'typescript.progress'?: boolean + /** + * Whether to show compile errors on lines (Default: false) + */ + 'typescript.diagnostics.enable'?: boolean + /** + * Settings to be written into an npmrc in key/value format. Can be used to specify custom registries and tokens. + */ + 'typescript.npmrc'?: { + [k: string]: unknown + } + /** + * Whether to restart the language server after dependencies were installed (default true) + */ + 'typescript.restartAfterDependencyInstallation'?: boolean + /** + * The log level to pass to the TypeScript language server. Logs will be forwarded to the browser console with the prefix [langserver]. + */ + 'typescript.langserver.log'?: false | 'log' | 'info' | 'warn' | 'error' + /** + * The log level to pass to tsserver. Logs will be forwarded to the browser console with the prefix [tsserver]. + */ + 'typescript.tsserver.log'?: false | 'terse' | 'normal' | 'requestTime' | 'verbose' } diff --git a/shared/providers.ts b/shared/providers.ts index 3fb98257c..06dd9af01 100644 --- a/shared/providers.ts +++ b/shared/providers.ts @@ -321,6 +321,9 @@ export function createReferencesProvider( const lsifFiles = new Set(lsifResults.map(file)) + const disableMixedResults = sourcegraph.configuration.get().get('codeIntel.disableMixedResults') ?? false + if (disableMixedResults && lsifFiles.size > 0) return + for await (const rawResults of searchProvider(textDocument, position, context)) { // Filter out any search results that occur in the same file as LSIF results. These // results are definitely incorrect and will pollute the ordering of precise and fuzzy diff --git a/shared/search/settings.ts b/shared/search/settings.ts index 3b86d3725..906a5ff23 100644 --- a/shared/search/settings.ts +++ b/shared/search/settings.ts @@ -6,33 +6,37 @@ */ export interface SearchBasedCodeIntelligenceSettings { - /** - * Whether to use pre-computed LSIF data for code intelligence (such as hovers, definitions, and references). See https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence. - */ - 'codeIntel.lsif'?: boolean - /** - * Whether to enable trace logging on the extension. - */ - 'codeIntel.traceExtension'?: boolean - /** - * Whether to fetch multiple precise definitions and references on hover. - */ - 'codeIntel.disableRangeQueries'?: boolean - /** - * Whether to include forked repositories in search results. - */ - 'basicCodeIntel.includeForks'?: boolean - /** - * Whether to include archived repositories in search results. - */ - 'basicCodeIntel.includeArchives'?: boolean - /** - * Whether to use only indexed requests to the search API. - */ - 'basicCodeIntel.indexOnly'?: boolean - /** - * The timeout (in milliseconds) for un-indexed search requests. - */ - 'basicCodeIntel.unindexedSearchTimeout'?: number - [k: string]: unknown + /** + * Whether to use pre-computed LSIF data for code intelligence (such as hovers, definitions, and references). See https://docs.sourcegraph.com/code_intelligence/explanations/precise_code_intelligence. + */ + 'codeIntel.lsif'?: boolean + /** + * Whether to enable trace logging on the extension. + */ + 'codeIntel.traceExtension'?: boolean + /** + * Whether to fetch multiple precise definitions and references on hover. + */ + 'codeIntel.disableRangeQueries'?: boolean + /** + * If true, do not show 'search-based' results alongside LSIF results. + */ + 'codeIntel.disableMixedResults'?: boolean + /** + * Whether to include forked repositories in search results. + */ + 'basicCodeIntel.includeForks'?: boolean + /** + * Whether to include archived repositories in search results. + */ + 'basicCodeIntel.includeArchives'?: boolean + /** + * Whether to use only indexed requests to the search API. + */ + 'basicCodeIntel.indexOnly'?: boolean + /** + * The timeout (in milliseconds) for un-indexed search requests. + */ + 'basicCodeIntel.unindexedSearchTimeout'?: number + [k: string]: unknown }