How to use the sourcegraph.TextEdit 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 / findReplace.ts View on Github external
},
    })
    if (errors && errors.length > 0) {
        throw new Error(`GraphQL response error: ${errors[0].message}`)
    }
    const canonicalURLs: string[] = data.comby.results.map(
        (r: any) => `git://${r.file.commit.repository.name}?${r.file.commit.oid}#${r.file.path}`
    )
    const docs = await Promise.all(canonicalURLs.map(url => sourcegraph.workspace.openTextDocument(new URL(url))))

    const edit = new sourcegraph.WorkspaceEdit()
    for (const [i, doc] of docs.entries()) {
        if (doc.text!.length > 15000) {
            continue // TODO!(sqs): skip too large
        }
        edit.set(new URL(doc.uri), [sourcegraph.TextEdit.patch(data.comby.results[i].rawDiff)])
    }

    return (edit as any).toJSON()
}
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / execServer / editsForCommands.ts View on Github external
map(result => {
                    const edit = new sourcegraph.WorkspaceEdit()
                    for (const file of files) {
                        const name = path.basename(parseRepoURI(file.uri).filePath!)
                        const patch = result.fileDiffs![name]
                        if (patch) {
                            edit.set(new URL(file.uri), [sourcegraph.TextEdit.patch(patch)])
                        }
                    }
                    return edit
                })
            )
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / packageJsonDependency / packageManagerCommon.ts View on Github external
map(result => {
                    const edit = new sourcegraph.WorkspaceEdit()
                    for (const file of files) {
                        const name = path.basename(parseRepoURI(file.uri).filePath!)
                        edit.set(new URL(file.uri), [sourcegraph.TextEdit.patch(result.fileDiffs![name])])
                    }
                    return edit
                })
            )