Skip to content

Commit da1fb33

Browse files
author
Stephen Gutekanst
committed
share some code + rm tsconfig.json (I don't know how to fix it)
1 parent 45049f4 commit da1fb33

File tree

6 files changed

+26
-35
lines changed

6 files changed

+26
-35
lines changed

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as sourcegraph from 'sourcegraph'
2-
import { fetchDiscussionThreads } from './api'
3-
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'
2+
import { distanceInWordsToNow } from 'date-fns'
43
import { resolveSettings, Settings } from './settings'
4+
import { fetchDiscussionThreads } from './shared/api'
55

66
export function activate(): void {
77
function activeEditor(): sourcegraph.CodeEditor | undefined {

src/graphql.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as sourcegraph from 'sourcegraph'
2+
3+
export async function queryGraphQL(query: string, variables: any = {}): Promise<any> {
4+
return sourcegraph.commands.executeCommand<any>('queryGraphQL', query, variables)
5+
}

src/shared/SHARED.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This code is shared between:
2+
3+
- https://github.com/sourcegraph/sourcegraph-extension-api
4+
- https://github.com/sourcegraph/sourcegraph-vscode
5+
6+
Eventually it should be moved into an npm package somewhere. Until then, ensure
7+
you are updating both copies at the same time. Do not modify one and not modify
8+
the other.

src/api.ts renamed to src/shared/api.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
// TODO: This file is allllll copypasta (kind of)!
2-
3-
import * as sourcegraph from 'sourcegraph'
1+
import { queryGraphQL } from '../graphql'
42
import { createAggregateError } from './errors'
53

6-
async function queryGraphQL(query: string, variables: any = {}) {
7-
return sourcegraph.commands.executeCommand<any>('queryGraphQL', query, variables)
8-
}
9-
104
const discussionCommentFieldsFragment = `
115
fragment DiscussionCommentFields on DiscussionComment {
126
id
@@ -21,7 +15,7 @@ const discussionCommentFieldsFragment = `
2115
`
2216

2317
function discussionThreadFieldsFragment(relativeRev?: string): string {
24-
var relativeRevFields: string = ''
18+
let relativeRevFields = ''
2519
if (relativeRev) {
2620
relativeRevFields = `
2721
relativePath(rev: $relativeRev)
@@ -84,11 +78,11 @@ function discussionThreadFieldsFragment(relativeRev?: string): string {
8478
*
8579
* @return Promise that emits the new discussion thread.
8680
*/
87-
async function createThread(
81+
export async function createThread(
8882
input: SourcegraphGQL.IDiscussionThreadCreateInput,
89-
relativeRev: string = ''
83+
relativeRev = ''
9084
): Promise<SourcegraphGQL.IDiscussionThread> {
91-
let { data, errors } = await queryGraphQL(
85+
const { data, errors } = await queryGraphQL(
9286
`
9387
mutation CreateThread($input: DiscussionThreadCreateInput!, $relativeRev: String!) {
9488
discussions {
@@ -125,7 +119,7 @@ export async function fetchDiscussionThreads(opts: {
125119
relativeRev?: string
126120
}): Promise<SourcegraphGQL.IDiscussionThreadConnection> {
127121
opts.relativeRev = opts.relativeRev || ''
128-
let { data, errors } = await queryGraphQL(
122+
const { data, errors } = await queryGraphQL(
129123
`
130124
query DiscussionThreads(
131125
$first: Int
@@ -175,9 +169,9 @@ export async function fetchDiscussionThreads(opts: {
175169
*/
176170
export async function fetchDiscussionThreadAndComments(
177171
threadID: string,
178-
relativeRev: string = ''
172+
relativeRev = ''
179173
): Promise<SourcegraphGQL.IDiscussionThread> {
180-
let { data, errors } = await queryGraphQL(
174+
const { data, errors } = await queryGraphQL(
181175
`
182176
query DiscussionThreadComments($threadID: ID!, $relativeRev: String!) {
183177
discussionThreads(threadID: $threadID) {
@@ -217,9 +211,9 @@ export async function fetchDiscussionThreadAndComments(
217211
export async function addCommentToThread(
218212
threadID: string,
219213
contents: string,
220-
relativeRev: string = ''
214+
relativeRev = ''
221215
): Promise<SourcegraphGQL.IDiscussionThread> {
222-
let { data, errors } = await queryGraphQL(
216+
const { data, errors } = await queryGraphQL(
223217
`
224218
mutation AddCommentToThread($threadID: ID!, $contents: String!, $relativeRev: String!) {
225219
discussions {
@@ -251,7 +245,7 @@ export async function addCommentToThread(
251245
* @return Promise that emits the HTML string, which is already sanitized and escaped and thus is always safe to render.
252246
*/
253247
export async function renderMarkdown(markdown: string, options?: SourcegraphGQL.IMarkdownOptions): Promise<string> {
254-
let { data, errors } = await queryGraphQL(
248+
const { data, errors } = await queryGraphQL(
255249
`
256250
query RenderMarkdown($markdown: String!, $options: MarkdownOptions) {
257251
renderMarkdown(markdown: $markdown, options: $options)

src/errors.ts renamed to src/shared/errors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// TODO: This file is allllll copypasta!
2-
31
export interface ErrorLike {
42
message: string
53
code?: string

tsconfig.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)