Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function computeFixAllAction(): Promise> {
// TODO!(sqs): Make this listen for new diagnostics and include those too, but that might be
// super inefficient because it's n^2, so maybe an altogether better/different solution is
// needed.
const allImportStarDiags = sourcegraph.languages
.getDiagnostics()
.map(([uri, diagnostics]) => {
const matchingDiags = diagnostics.filter(isImportStarDiagnostic)
return matchingDiags.length > 0
? ([uri, matchingDiags] as ReturnType[0])
: null
})
.filter(isDefined)
const edit = new sourcegraph.WorkspaceEdit()
for (const [uri, diags] of allImportStarDiags) {
const doc = await sourcegraph.workspace.openTextDocument(uri)
for (const diag of diags) {
computeFixEdit(diag, doc, edit)
}
}
return { edit, diagnostics: flatten(allImportStarDiags.map(([, diagnostics]) => diagnostics)) }
disableRuleEdits.insert(
new URL(doc.uri),
new sourcegraph.Position(diag.range.start.line, 0),
'// sourcegraph:ignore-next-line React lint https://sourcegraph.example.com/ofYRz6NFzj\n'
)
return [
{
title: 'Extract Props type',
edit: fixEdits,
diagnostics: flatten(sourcegraph.languages.getDiagnostics().map(([, diagnostics]) => diagnostics)),
},
{
title: 'Ignore',
edit: disableRuleEdits,
diagnostics: flatten(sourcegraph.languages.getDiagnostics().map(([, diagnostics]) => diagnostics)),
},
...OTHER_CODE_ACTIONS,
]
},
}
ctx.subscriptions.add(
sourcegraph.languages.registerHoverProvider(goFiles, {
provideHover: asyncFirst([lsif.hover, lsp.hover, wrapMaybe(basicCodeIntel.hover)], null),
})
)
ctx.subscriptions.add(
sourcegraph.languages.registerDefinitionProvider(goFiles, {
provideDefinition: asyncFirst(
[lsif.definition, lsp.definition, wrapMaybe(basicCodeIntel.definition)],
null
),
})
)
ctx.subscriptions.add(
sourcegraph.languages.registerReferenceProvider(goFiles, {
provideReferences: async (doc, pos) => {
if (isLSPEnabled()) {
const references = await lsp.references(doc, pos)
return references ? references.value : null
}
// Gets an opaque value that is the same for all locations
// within a file but different from other files.
const file = (loc: sourcegraph.Location) => `${loc.uri.host} ${loc.uri.pathname} ${loc.uri.hash}`
// Concatenates LSIF results (if present) with fuzzy results
// because LSIF data might be sparse.
const lsifReferences = await lsif.references(doc, pos)
const fuzzyReferences = (await basicCodeIntel.references(doc, pos)) || []
const lsifFiles = new Set((lsifReferences ? lsifReferences.value : []).map(file))
const lsif = initLSIF()
const handler = new Handler({
...languageSpec.handlerArgs,
sourcegraph,
})
const selector = documentSelector(languageSpec.handlerArgs.fileExts)
ctx.subscriptions.add(
sourcegraph.languages.registerHoverProvider(selector, {
provideHover: asyncFirst(
[lsif.hover, wrapMaybe(handler.hover.bind(handler))],
null
),
})
)
ctx.subscriptions.add(
sourcegraph.languages.registerDefinitionProvider(selector, {
provideDefinition: asyncFirst(
[
lsif.definition,
wrapMaybe(handler.definition.bind(handler)),
],
null
),
})
)
ctx.subscriptions.add(
sourcegraph.languages.registerReferenceProvider(selector, {
provideReferences: async (doc, pos) => {
// Gets an opaque value that is the same for all locations
// within a file but different from other files.
const file = (loc: sourcegraph.Location) =>
`${loc.uri.host} ${loc.uri.pathname} ${loc.uri.hash}`
export function register(): Unsubscribable {
const subscriptions = new Subscription()
subscriptions.add(
sourcegraph.workspace.registerDiagnosticProvider('packageJsonDependency', {
provideDiagnostics: (_scope, context) =>
provideDiagnostics(context).pipe(
filter((diagnostics): diagnostics is sourcegraph.Diagnostic[] => diagnostics !== LOADING)
),
})
)
subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
subscriptions.add(
sourcegraph.commands.registerActionEditCommand(REMOVE_COMMAND, async diagnostic => {
const doc = await sourcegraph.workspace.openTextDocument(diagnostic.resource)
return computeRemoveDependencyEdit(diagnostic, doc)
})
)
return subscriptions
}
export function register(): Unsubscribable {
const subscriptions = new Subscription()
subscriptions.add(
sourcegraph.workspace.registerDiagnosticProvider('npmCredentials', {
provideDiagnostics: (_scope, context) =>
provideDiagnostics((context as any) as NPMCredentialsCampaignContext).pipe(
filter((diagnostics): diagnostics is sourcegraph.Diagnostic[] => diagnostics !== LOADING)
),
})
)
subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
subscriptions.add(
sourcegraph.commands.registerActionEditCommand(NPM_CREDENTIALS_FIX_COMMAND, diagnostic => {
if (!diagnostic) {
return new sourcegraph.WorkspaceEdit()
}
return computeFixEdit(diagnostic)
})
)
return subscriptions
}
function startDiagnostics(): Unsubscribable {
const subscriptions = new Subscription()
const diagnosticsCollection = sourcegraph.languages.createDiagnosticCollection('dependencyRules')
subscriptions.add(diagnosticsCollection)
subscriptions.add(
diagnostics.subscribe(entries => {
diagnosticsCollection.set(entries)
})
)
return diagnosticsCollection
}
export function registerTravisGo(): Unsubscribable {
const subscriptions = new Subscription()
subscriptions.add(startDiagnostics())
subscriptions.add(registerStatusProvider(diagnostics, diagnosticCollection))
subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
return subscriptions
}
return null
}
const locations = Array.isArray(body) ? body : [body]
return convertLocations(
sourcegraph,
locations.map((definition: LSP.Location) => ({
...definition,
uri: setPath(doc, definition.uri),
}))
)
},
})
)
ctx.subscriptions.add(
sourcegraph.languages.registerReferenceProvider(['*'], {
provideReferences: async (doc, position) => {
if (!(await hasLSIF(doc))) {
return null
}
const locations: LSP.Location[] | null = await send({
doc,
method: 'references',
path: pathFromDoc(doc),
position,
})
if (!locations) {
return null
}
return convertLocations(
sourcegraph,
locations.map((reference: LSP.Location) => ({
function startDiagnostics(): Unsubscribable {
const subscriptions = new Subscription()
const diagnosticsCollection = sourcegraph.languages.createDiagnosticCollection('codeOwnership')
subscriptions.add(diagnosticsCollection)
subscriptions.add(
from(sourcegraph.workspace.rootChanges)
.pipe(
startWith(void 0),
map(() => sourcegraph.workspace.roots.filter(propertyIsDefined('baseUri'))),
switchMap(async roots => {
return combineLatestOrDefault(
roots
.map(async (root, rootI) => {
const base = parseRepoURI(root.baseUri.toString())
const head = parseRepoURI(root.uri.toString())
const data = dataOrThrowErrors(
await queryGraphQL({
query: gql`
query ComparisonRawDiff(