diff --git a/generator/src/main.ts b/generator/src/main.ts index f6e209eb3..a50c96c55 100644 --- a/generator/src/main.ts +++ b/generator/src/main.ts @@ -104,7 +104,7 @@ function main(): void { ) shell.sed( '-i', - /"description": ".*"/, + /^ "description": ".*"/, `"description": "Provides basic code intelligence for ${stylized} using the Sourcegraph search API"`, 'package.json' ) @@ -114,6 +114,26 @@ function main(): void { `"url": "https://github.com/sourcegraph/sourcegraph-${languageID}"`, 'package.json' ) + shell.sed( + '-i', + /GENERATOR:IMPRECISE_RESULTS_URL/, + langSpec.hasLanguageServer + ? `https://github.com/sourcegraph/sourcegraph-${ + langSpec.handlerArgs.languageID + }` + : `https://github.com/sourcegraph/sourcegraph-${ + langSpec.handlerArgs.languageID + }#limitations`, + 'package.json' + ) + shell.sed( + '-i', + /"These locations are computed using heuristics.*"/, + langSpec.hasLanguageServer + ? `These locations are computed using heuristics. Use a language server for precise results."` + : `These locations are computed using heuristics.`, + 'package.json' + ) shell.sed('-i', /\$LANGNAME\b/, languageID, 'README.md') shell.sed('-i', /\$LANG\b/, stylized, 'README.md') shell.sed( diff --git a/languages.ts b/languages.ts index f50838a37..ac4046b22 100644 --- a/languages.ts +++ b/languages.ts @@ -5,6 +5,7 @@ type Omit = Pick> export type LanguageSpec = { handlerArgs: Omit stylized: string + hasLanguageServer?: boolean } const cStyleBlock = { @@ -59,6 +60,7 @@ export const languages: LanguageSpec[] = [ commentStyle: cStyle, }, stylized: 'TypeScript', + hasLanguageServer: true, }, { handlerArgs: { @@ -75,6 +77,7 @@ export const languages: LanguageSpec[] = [ }, }, stylized: 'Python', + hasLanguageServer: true, }, { handlerArgs: { @@ -98,6 +101,7 @@ export const languages: LanguageSpec[] = [ }, }, stylized: 'Go', + hasLanguageServer: true, }, { handlerArgs: { diff --git a/package/package.json b/package/package.json index 5c2e4b095..22d683b91 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "@sourcegraph/basic-code-intel", - "version": "6.0.5", + "version": "6.0.6", "description": "Common library for providing basic code intelligence in Sourcegraph extensions", "repository": { "type": "git", diff --git a/package/src/index.ts b/package/src/index.ts index 2e271dfe4..4fd9f8bab 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -4,13 +4,17 @@ import { Handler, documentSelector, HandlerArgs } from './handler' // No-op for Sourcegraph versions prior to 3.0-preview const DUMMY_CTX = { subscriptions: { add: (_unsubscribable: any) => void 0 } } +type Omit = Pick> + export function activateBasicCodeIntel( - args: HandlerArgs + args: Omit ): (ctx: sourcegraph.ExtensionContext) => void { return function activate( ctx: sourcegraph.ExtensionContext = DUMMY_CTX ): void { - const h = new Handler(args) + const h = new Handler({ ...args, sourcegraph }) + + sourcegraph.internal.updateContext({ isImprecise: true }) ctx.subscriptions.add( sourcegraph.languages.registerHoverProvider( diff --git a/template/package.json b/template/package.json index 3d814c9d7..db9d0db0c 100644 --- a/template/package.json +++ b/template/package.json @@ -18,6 +18,28 @@ "*" ], "contributes": { + "actions": [ + { + "id": "impreciseResults", + "title": "Imprecise results", + "command": "open", + "commandArguments": [ + "GENERATOR:IMPRECISE_RESULTS_URL" + ], + "actionItem": { + "label": "Imprecise results", + "description": "These locations are computed using heuristics. (If available:) use a language server for precise results." + } + } + ], + "menus": { + "panel/toolbar": [ + { + "action": "impreciseResults", + "when": "isImprecise" + } + ] + }, "configuration": { "title": "Basic code intelligence settings", "properties": { diff --git a/template/src/extension.ts b/template/src/extension.ts index e6726ba54..e306573a4 100644 --- a/template/src/extension.ts +++ b/template/src/extension.ts @@ -4,6 +4,6 @@ import * as spec from '../../languages' export function activate(ctx: sourcegraph.ExtensionContext): void { for (const language of spec.languages) { - activateBasicCodeIntel({ ...language.handlerArgs, sourcegraph })(ctx) + activateBasicCodeIntel(language.handlerArgs)(ctx) } }