diff --git a/package/package.json b/package/package.json index 32c8f288c..da42a01db 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "@sourcegraph/basic-code-intel", - "version": "6.0.15", + "version": "6.0.16", "description": "Common library for providing basic code intelligence in Sourcegraph extensions", "repository": { "type": "git", diff --git a/package/src/handler.ts b/package/src/handler.ts index 4d3935b52..0307bc600 100644 --- a/package/src/handler.ts +++ b/package/src/handler.ts @@ -1,3 +1,4 @@ +import { concat, Subscription, from } from 'rxjs' import { API, Result, parseUri } from './api' import { takeWhile, dropWhile, sortBy, flatten, omit } from 'lodash' import { @@ -456,6 +457,55 @@ export function findDocstring({ return docLines && unmungeLines(docLines).join('\n') } +export function registerFeedbackButton({ + languageID, + sourcegraph, + isPrecise, +}: { + languageID: string + isPrecise: boolean + sourcegraph: typeof import('sourcegraph') +}): Subscription { + if (sourcegraph.configuration.get().get('codeIntel.showFeedback')) { + return concat( + // Update the context once upon page load... + from(sourcegraph.workspace.textDocuments), + // ...and whenever a document is opened. + sourcegraph.workspace.onDidOpenTextDocument + ).subscribe(document => { + sourcegraph.internal.updateContext({ + showFeedback: true, + 'codeIntel.feedbackLink': feedbackLink({ + currentFile: document && document.uri, + language: languageID, + kind: isPrecise ? 'Precise' : 'Default', + }).href, + }) + }) + } + return Subscription.EMPTY +} + +function feedbackLink({ + currentFile, + language, + kind, +}: { + currentFile?: string + language: string + kind: 'Default' | 'Precise' +}): URL { + const url = new URL( + 'https://docs.google.com/forms/d/e/1FAIpQLSfmn4M3nVj6R5m8UuAor_4ft8IMhieND_Uu8AlerhGO7X9C9w/viewform?usp=pp_url' + ) + if (currentFile) { + url.searchParams.append('entry.1135698969', currentFile) + } + url.searchParams.append('entry.55312909', language) + url.searchParams.append('entry.1824476739', kind) + return url +} + /** * @see package.json contributes.configuration section for the configuration schema. */ diff --git a/package/src/index.ts b/package/src/index.ts index 1ae6113b7..f43c64259 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -1,7 +1,7 @@ import * as sourcegraph from 'sourcegraph' import { Handler, HandlerArgs, documentSelector } from './handler' -export { Handler, HandlerArgs } from './handler' +export { Handler, HandlerArgs, registerFeedbackButton } from './handler' // No-op for Sourcegraph versions prior to 3.0-preview const DUMMY_CTX = { subscriptions: { add: (_unsubscribable: any) => void 0 } } diff --git a/template/package.json b/template/package.json index 6a66adee1..e1e14c759 100644 --- a/template/package.json +++ b/template/package.json @@ -30,9 +30,27 @@ "label": "References: Search mode", "description": "Results come from text search and heuristics. (Language server mode is not available for $LANG.)/(To use a language server for precise results, ...)" } + }, + { + "id": "feedback", + "command": "open", + "title": "Submit code intel feedback", + "commandArguments": [ + "${get(context, `codeIntel.feedbackLink`)}" + ], + "actionItem": { + "description": "Submit code intel feedback", + "iconURL": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMCAwaDI0djI0SDB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTExLjk5IDJDNi40NyAyIDIgNi40OCAyIDEyczQuNDcgMTAgOS45OSAxMEMxNy41MiAyMiAyMiAxNy41MiAyMiAxMlMxNy41MiAyIDExLjk5IDJ6TTEyIDIwYy00LjQyIDAtOC0zLjU4LTgtOHMzLjU4LTggOC04IDggMy41OCA4IDgtMy41OCA4LTggOHptMy41LTljLjgzIDAgMS41LS42NyAxLjUtMS41UzE2LjMzIDggMTUuNSA4IDE0IDguNjcgMTQgOS41cy42NyAxLjUgMS41IDEuNXptLTcgMGMuODMgMCAxLjUtLjY3IDEuNS0xLjVTOS4zMyA4IDguNSA4IDcgOC42NyA3IDkuNSA3LjY3IDExIDguNSAxMXptMy41IDYuNWMyLjMzIDAgNC4zMS0xLjQ2IDUuMTEtMy41SDYuODljLjggMi4wNCAyLjc4IDMuNSA1LjExIDMuNXoiLz48L3N2Zz4=" + } } ], "menus": { + "editor/title": [ + { + "action": "feedback", + "when": "showFeedback" + } + ], "panel/toolbar": [ { "action": "impreciseResults", diff --git a/template/src/extension.ts b/template/src/extension.ts index 5e8427feb..3d35381e7 100644 --- a/template/src/extension.ts +++ b/template/src/extension.ts @@ -1,4 +1,4 @@ -import { Handler, HandlerArgs } from '../../package/lib' +import { Handler, HandlerArgs, registerFeedbackButton } from '../../package/lib' import * as sourcegraph from 'sourcegraph' import { languageSpecs } from '../../languages' import { documentSelector } from '../../package/lib/handler' @@ -31,6 +31,14 @@ function activateWithArgs( sourcegraph.internal.updateContext({ isImprecise: true }) + ctx.subscriptions.add( + registerFeedbackButton({ + languageID: args.languageID, + sourcegraph, + isPrecise: false, + }) + ) + ctx.subscriptions.add( sourcegraph.languages.registerHoverProvider( documentSelector(h.fileExts),