How to use the sourcegraph.workspace 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 / check-search / src / importStar.ts View on Github external
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)) }
}
github sourcegraph / sourcegraph-typescript / src / extension / extension.ts View on Github external
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()) {
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / dependencyManagement / register.ts View on Github external
export function registerDependencyManagementProviders<
    Q extends DependencyQuery,
    S extends DependencySpecificationWithType<q>
&gt;(
    id: string,
    provider: WithoutType&gt;,
    parseQuery: (context: sourcegraph.ContextValues) =&gt; 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) =&gt;
                provideDependencyManagementDiagnostics(
                    provider,
                    DEPENDENCY_ID,
                    parseQuery(context),
                    (context as unknown) as DependencyManagementCampaignContextCommon
                ),
        })
    )
    subscriptions.add(
        sourcegraph.languages.registerCodeActionProvider(['*'], {
            provideCodeActions: (_doc, _rangeOrSelection, context): Observable =&gt;
                combineLatest(
                    context.diagnostics
                        .map(diagnostic =&gt; parseDependencyManagementDiagnostic(diagnostic, DEPENDENCY_ID))
                        .filter(isDefined)</q>
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / rubyGemDependency / rubyGemDependency.ts View on Github external
sourcegraph.commands.registerActionEditCommand(REMOVE_COMMAND, async diagnostic =>
            diagnostic
                ? computeRemoveDependencyEdit(
                      diagnostic,
                      await sourcegraph.workspace.openTextDocument(diagnostic.resource)
                  )
                : new sourcegraph.WorkspaceEdit()
        )
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / travisGo.ts View on Github external
async function computeFixAllActionsFromDiagnostics(
    diagnostics: sourcegraph.Diagnostic[]
): Promise&gt; {
    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 }
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / codeOwnership.ts View on Github external
                map(() => sourcegraph.workspace.roots.filter(propertyIsDefined('baseUri'))),
                switchMap(async roots => {
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / findReplace.ts View on Github external
    const docs = await Promise.all(canonicalURLs.map(url => sourcegraph.workspace.openTextDocument(new URL(url))))