Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let definitionURI: sourcegraph.URI
if (/^file:\/\/\//.test(uriFromLangServer)) {
// The definition is in a file in the same repo
const docURL = new URL(currentDocURI)
docURL.hash = uriFromLangServer.slice('file:///'.length)
definitionURI = new sourcegraph.URI(docURL.href)
} else {
definitionURI = new sourcegraph.URI(uriFromLangServer)
}
return new sourcegraph.Location(
definitionURI,
range &&
new sourcegraph.Range(
new sourcegraph.Position(range.start.line, range.start.character),
new sourcegraph.Position(range.end.line, range.end.character)
)
)
}
}): sourcegraph.Location => {
let definitionURI: sourcegraph.URI
if (/^file:\/\/\//.test(uriFromLangServer)) {
// The definition is in a file in the same repo
const docURL = new URL(currentDocURI)
docURL.hash = uriFromLangServer.slice('file:///'.length)
definitionURI = new sourcegraph.URI(docURL.href)
} else {
definitionURI = new sourcegraph.URI(uriFromLangServer)
}
return new sourcegraph.Location(
definitionURI,
range &&
new sourcegraph.Range(
new sourcegraph.Position(range.start.line, range.start.character),
new sourcegraph.Position(range.end.line, range.end.character)
)
)
}
provideCodeActions: async (doc, _rangeOrSelection, context): Promise => {
const diag = context.diagnostics.find(d => d.tags && d.tags.includes(TAG_NO_INLINE_PROPS))
if (!diag) {
return []
}
const fixEdits = new sourcegraph.WorkspaceEdit()
const typeBody = doc.text.slice(doc.offsetAt(diag.range.start), doc.offsetAt(diag.range.end))
fixEdits.insert(
new URL(doc.uri),
new sourcegraph.Position(diag.range.start.line, 0),
`interface Props ${typeBody}\n\n`
)
fixEdits.replace(new URL(doc.uri), diag.range, 'Props')
const disableRuleEdits = new sourcegraph.WorkspaceEdit()
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)),
const addBundlerRemoveEdits = async (
gemfile: sourcegraph.TextDocument,
edit: sourcegraph.WorkspaceEdit
): Promise => {
const p = parseRepoURI(gemfile.uri)
const result = await bundlerRemove(dep.name, { repository: p.repoName, commit: p.commitID! })
for (const path of Object.keys(result.files!)) {
const uri = new URL(gemfile.uri.replace('Gemfile', '') + path)
const doc = await sourcegraph.workspace.openTextDocument(uri)
if (doc.text !== result.files![path]) {
edit.replace(
uri,
new sourcegraph.Range(new sourcegraph.Position(0, 0), doc.positionAt(doc.text!.length)),
result.files![path]
)
}
}
}
const addIndirectDependencyEdits = (gemfile: sourcegraph.TextDocument, edit: sourcegraph.WorkspaceEdit): void => {
function rangeForLintMessage(doc: sourcegraph.TextDocument, m: Linter.LintMessage): sourcegraph.Range {
if (m.line === undefined && m.column === undefined) {
return new sourcegraph.Range(0, 0, 1, 0)
}
const start = new sourcegraph.Position(m.line - 1, m.column - 1)
let end: sourcegraph.Position
if (m.endLine === undefined && m.endColumn === undefined) {
const wordRange = doc.getWordRangeAtPosition(start)
end = wordRange ? wordRange.end : start
} else {
end = new sourcegraph.Position(m.endLine - 1, m.endColumn - 1)
}
return new sourcegraph.Range(start, end)
}
function rangeForLintMessage(doc: sourcegraph.TextDocument, m: Linter.LintMessage): sourcegraph.Range {
if (m.line === undefined && m.column === undefined) {
return new sourcegraph.Range(0, 0, 1, 0)
}
const start = new sourcegraph.Position(m.line - 1, m.column - 1)
let end: sourcegraph.Position
if (m.endLine === undefined && m.endColumn === undefined) {
const wordRange = doc.getWordRangeAtPosition(start)
end = wordRange ? wordRange.end : start
} else {
end = new sourcegraph.Position(m.endLine - 1, m.endColumn - 1)
}
return new sourcegraph.Range(start, end)
}
function duplicationRange({ start, end }: { start: ITokenLocation; end: ITokenLocation }): sourcegraph.Range {
return new sourcegraph.Range(
new sourcegraph.Position(start.line, start.column || 0),
new sourcegraph.Position(end.line, end.column || 0)
)
}
function duplicationRange({ start, end }: { start: ITokenLocation; end: ITokenLocation }): sourcegraph.Range {
return new sourcegraph.Range(
new sourcegraph.Position(start.line, start.column || 0),
new sourcegraph.Position(end.line, end.column || 0)
)
}