How to use the sourcegraph.commands function in sourcegraph

To help you get started, we’ve selected a few sourcegraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / packageJsonDependency / packageJsonDependency.ts View on Github external
export function register(): Unsubscribable {
    const subscriptions = new Subscription()
    subscriptions.add(
        sourcegraph.workspace.registerDiagnosticProvider('packageJsonDependency', {
            provideDiagnostics: (_scope, context) =>
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                provideDiagnostics((context as any) as PackageJsonDependencyCampaignContext).pipe(
                    filter((diagnostics): diagnostics is sourcegraph.Diagnostic[] => diagnostics !== LOADING)
                ),
        })
    )
    subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
    subscriptions.add(
        sourcegraph.commands.registerActionEditCommand(COMMAND_ID, diagnostic => {
            if (!diagnostic || (diagnostic.tags && !diagnostic.tags.includes('fix'))) {
                return Promise.resolve(new sourcegraph.WorkspaceEdit())
            }
            return editForDependencyAction(diagnostic).toPromise()
        })
    )
    return subscriptions
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / packageJsonDependency.ts View on Github external
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
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / codeDuplication.ts View on Github external
export function register(): Unsubscribable {
    const subscriptions = new Subscription()
    subscriptions.add(startDiagnostics())
    subscriptions.add(registerCheckProvider(diagnostics))
    subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
    subscriptions.add(
        sourcegraph.commands.registerActionEditCommand(FILE_ISSUE_COMMAND, () => new sourcegraph.WorkspaceEdit())
    )
    subscriptions.add(sourcegraph.commands.registerActionEditCommand(IGNORE_COMMAND, ignoreCommandCallback))
    return subscriptions
}
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / rubyGemDependency / rubyGemDependency.ts View on Github external
export function register(): Unsubscribable {
    const subscriptions = new Subscription()
    subscriptions.add(
        sourcegraph.workspace.registerDiagnosticProvider('rubyGemDependency', {
            provideDiagnostics: (_scope, context) =>
                provideDiagnostics((context as any) as RubyGemDependencyCampaignContext).pipe(
                    filter((diagnostics): diagnostics is sourcegraph.Diagnostic[] => diagnostics !== LOADING)
                ),
        })
    )
    subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
    subscriptions.add(
        sourcegraph.commands.registerActionEditCommand(REMOVE_COMMAND, async diagnostic =>
            diagnostic
                ? computeRemoveDependencyEdit(
                      diagnostic,
                      await sourcegraph.workspace.openTextDocument(diagnostic.resource)
                  )
                : new sourcegraph.WorkspaceEdit()
        )
    )
    return subscriptions
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / codeDuplication.ts View on Github external
export function register(): Unsubscribable {
    const subscriptions = new Subscription()
    subscriptions.add(startDiagnostics())
    subscriptions.add(registerCheckProvider(diagnostics))
    subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
    subscriptions.add(
        sourcegraph.commands.registerActionEditCommand(FILE_ISSUE_COMMAND, () => new sourcegraph.WorkspaceEdit())
    )
    subscriptions.add(sourcegraph.commands.registerActionEditCommand(IGNORE_COMMAND, ignoreCommandCallback))
    return subscriptions
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / travisGo.ts View on Github external
{
                                                command: {
                                                    command: 'TODO!(sqs)',
                                                },
                                            },
                                        ],
                                    },
                                },
                            ],
                        },
                    ])
                ),
        })
    )
    subscriptions.add(
        sourcegraph.commands.registerActionEditCommand(
            FIX_GO_VERSION_COMMAND_ID,
            async (diagnostic: sourcegraph.Diagnostic) => {
                const { edit } = await computeFixAllActionsFromDiagnostics([diagnostic])
                return edit
            }
        )
    )
    return subscriptions
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / util.ts View on Github external
async ({ query, vars }: { query: string; vars: { [name: string]: any } }): Promise => {
        return sourcegraph.commands.executeCommand('queryGraphQL', query, vars)
    },
    arg => JSON.stringify({ query: arg.query, vars: arg.vars })
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / findReplace.ts View on Github external
export function register(): Unsubscribable {
    const subscriptions = new Subscription()
    subscriptions.add(sourcegraph.commands.registerCommand(FIND_REPLACE_REWRITE_COMMAND, rewrite))
    return subscriptions
}
github sourcegraph / sourcegraph-go / src / lang-go.ts View on Github external
async function queryGraphQL(query: string, variables: any = {}): Promise {
    const { data, errors } = await sourcegraph.commands.executeCommand('queryGraphQL', query, variables)
    if (errors) {
        throw Object.assign(new Error(errors.map((err: any) => err.message).join('\n')), { errors })
    }
    return data
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / eslint.ts View on Github external
export function register(): Unsubscribable {
    const subscriptions = new Subscription()
    subscriptions.add(startDiagnostics())
    subscriptions.add(registerCheckProvider(diagnostics))
    subscriptions.add(sourcegraph.languages.registerCodeActionProvider(['*'], createCodeActionProvider()))
    subscriptions.add(sourcegraph.commands.registerActionEditCommand(FIX_EDIT_COMMAND, fixEditCommandCallback))
    subscriptions.add(
        sourcegraph.commands.registerActionEditCommand(DISABLE_RULE_ON_LINE_COMMAND, disableRuleOnLineCommandCallback)
    )
    return subscriptions
}