Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

Add button to submit feedback #100

Merged
merged 5 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
50 changes: 50 additions & 0 deletions package/src/handler.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion package/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 } }
Expand Down
18 changes: 18 additions & 0 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion template/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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),
Expand Down