Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Implementations panel.
const IMPL_ID = 'go.impl' // implementations panel and provider ID
ctx.subscriptions.add(
sourcegraph.languages.registerLocationProvider(IMPL_ID, [{ pattern: '*.go' }], {
provideLocations: async (doc: sourcegraph.TextDocument, pos: sourcegraph.Position) => {
const response = await sendRequest({
rootURI: rootURIFromDoc(doc),
requestType: lspProtocol.ImplementationRequest.type,
request: positionParams(doc, pos),
useCache: true,
})
return convert.references({ currentDocURI: doc.uri, references: response })
},
})
)
const panelView = sourcegraph.app.createPanelView(IMPL_ID)
panelView.title = 'Go ifaces/impls'
panelView.component = { locationProvider: IMPL_ID }
panelView.priority = 160
ctx.subscriptions.add(panelView)
}
import * as sourcegraph from 'sourcegraph'
import { codecovToDecorations } from './decoration'
import {
getCommitCoverageRatio,
getFileCoverageRatios,
getFileLineCoverage,
} from './model'
import { resolveEndpoint, resolveSettings, Settings } from './settings'
import {
codecovParamsForRepositoryCommit,
resolveDocumentURI,
resolveRootURI,
} from './uri'
const decorationType =
sourcegraph.app.createDecorationType &&
sourcegraph.app.createDecorationType()
/** Entrypoint for the Codecov Sourcegraph extension. */
export function activate(): void {
function activeEditors(): sourcegraph.CodeEditor[] {
return sourcegraph.app.activeWindow
? sourcegraph.app.activeWindow.visibleViewComponents
: []
}
// When the configuration or current file changes, publish new decorations.
//
// TODO: Unpublish decorations on previously (but not currently) open files when settings changes, to avoid a
// brief flicker of the old state when the file is reopened.
async function decorate(editors = activeEditors()): Promise {
const settings = resolveSettings(
function activeEditors(): sourcegraph.CodeEditor[] {
return sourcegraph.app.activeWindow
? sourcegraph.app.activeWindow.visibleViewComponents
: []
}
}
const implementationResult = (await sendTracedRequest(
connection,
ImplementationRequest.type,
implementationParams,
{ span, tracer, token }
)) as Location[] | Location | null
rewriteUris(implementationResult, toSourcegraphTextDocumentUri)
return convertLocations(implementationResult)
})
providers.add(
sourcegraph.languages.registerLocationProvider(IMPL_ID, documentSelector, {
provideLocations: provideImpls,
})
)
const panelView = sourcegraph.app.createPanelView(IMPL_ID)
panelView.title = 'Implementations'
panelView.component = { locationProvider: IMPL_ID }
panelView.priority = 160
providers.add(panelView)
}
}
}
? new LightstepTracer({ access_token: config.value['lightstep.token'], component_name: 'ext-lang-typescript' })
: new Tracer()
const accessToken = await getOrCreateAccessToken()
/** The Sourcegraph endpoint contactable by the server */
const serverSgEndpoint: SourcegraphEndpoint = {
url: new URL(config.value['typescript.sourcegraphUrl'] || sourcegraph.internal.sourcegraphURL.toString()),
accessToken,
}
/** The Sourcegraph endpoint contactable by the extension */
const clientSgEndpoint: SourcegraphEndpoint = {
url: new URL(sourcegraph.internal.sourcegraphURL.toString()),
accessToken,
}
const diagnosticsDecorationType = sourcegraph.app.createDecorationType()
const codeActionsDecorationType = sourcegraph.app.createDecorationType()
sourcegraph.commands.registerCommand('typescript.toggle', async () => {
const config = sourcegraph.configuration.get()
await config.update('typescript.enable', config.value['typescript.enable'] === false)
})
const enabled = new BehaviorSubject(config.value['typescript.enable'] !== false)
ctx.subscriptions.add(
from(config)
.pipe(
rxop.map(config => config['typescript.enable'] !== false),
rxop.distinctUntilChanged()
)
.subscribe(enabled)
)