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)) }
}
for (const viewComponent of appWindow.visibleViewComponents) {
if (viewComponent.document.uri === sourcegraphTextDocumentUri.href) {
viewComponent.setDecorations(
codeActionsDecorationType,
uniqWith(codeActionDecorations, isEqual)
)
viewComponent.setDecorations(
diagnosticsDecorationType,
params.diagnostics.map(convertDiagnosticToDecoration)
)
}
}
}
})
subscriptions.add(
sourcegraph.workspace.onDidOpenTextDocument.subscribe(() => {
for (const appWindow of sourcegraph.app.windows) {
for (const viewComponent of appWindow.visibleViewComponents) {
const diagnostics = diagnosticsByUri.get(viewComponent.document.uri) || []
viewComponent.setDecorations(
diagnosticsDecorationType,
diagnostics.map(convertDiagnosticToDecoration)
)
}
}
})
)
// Show progress reports
const progressReporters = new Map>()
const completeReporters = () => {
// Cleanup unfinished progress reports
for (const reporterPromise of progressReporters.values()) {
export function registerDependencyManagementProviders<
Q extends DependencyQuery,
S extends DependencySpecificationWithType<q>
>(
id: string,
provider: WithoutType>,
parseQuery: (context: sourcegraph.ContextValues) => Q
): Unsubscribable {
const COMMAND_ID = `dependencyManagement.${id}.action`
const DEPENDENCY_ID = `dependencyManagement.${id}`
const subscriptions = new Subscription()
subscriptions.add(
sourcegraph.workspace.registerDiagnosticProvider(DEPENDENCY_ID, {
provideDiagnostics: (_scope, context) =>
provideDependencyManagementDiagnostics(
provider,
DEPENDENCY_ID,
parseQuery(context),
(context as unknown) as DependencyManagementCampaignContextCommon
),
})
)
subscriptions.add(
sourcegraph.languages.registerCodeActionProvider(['*'], {
provideCodeActions: (_doc, _rangeOrSelection, context): Observable =>
combineLatest(
context.diagnostics
.map(diagnostic => parseDependencyManagementDiagnostic(diagnostic, DEPENDENCY_ID))
.filter(isDefined)</q>
sourcegraph.commands.registerActionEditCommand(REMOVE_COMMAND, async diagnostic =>
diagnostic
? computeRemoveDependencyEdit(
diagnostic,
await sourcegraph.workspace.openTextDocument(diagnostic.resource)
)
: new sourcegraph.WorkspaceEdit()
)
async function computeFixAllActionsFromDiagnostics(
diagnostics: sourcegraph.Diagnostic[]
): Promise> {
const edit = new sourcegraph.WorkspaceEdit()
for (const diag of diagnostics) {
const doc = await sourcegraph.workspace.openTextDocument(diag.resource)
computeFixEdit(diag, doc, edit)
}
return { edit, diagnostics: diagnostics }
}
map(() => sourcegraph.workspace.roots.filter(propertyIsDefined('baseUri'))),
switchMap(async roots => {
map(() => sourcegraph.workspace.roots),
switchMap(roots => {
map(() => sourcegraph.workspace.roots),
switchMap(async roots => {
const docs = await Promise.all(canonicalURLs.map(url => sourcegraph.workspace.openTextDocument(new URL(url))))