Skip to content

Remove LSIF support from src-cli #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/src/code_intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Usage:

The commands are:

upload uploads a SCIP or LSIF index
upload uploads a SCIP index

Use "src code-intel [command] -h" for more information about a command.
`
flagSet := flag.NewFlagSet("code-intel", flag.ExitOnError)
handler := func(args []string) error {
lsifCommands.run(flagSet, "src code-intel", usage, args)
codeintelCommands.run(flagSet, "src code-intel", usage, args)
return nil
}

Expand Down
36 changes: 8 additions & 28 deletions cmd/src/code_intel_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"net/url"
"os"
"path/filepath"
"strings"
"time"

Expand All @@ -28,7 +27,7 @@ func init() {
Examples:
Before running any of these, first use src auth to authenticate.
Alternately, use the SRC_ACCESS_TOKEN environment variable for
individual src-cli invocations.
individual src-cli invocations.

If run from within the project itself, src-cli will infer various
flags based on git metadata.
Expand All @@ -48,9 +47,6 @@ Examples:

$ src code-intel upload -github-token=BAZ, or
$ src code-intel upload -gitlab-token=BAZ

For any of these commands, an LSIF index (default name: dump.lsif) can be
used instead of a SCIP index (default name: index.scip).
`
codeintelCommands = append(codeintelCommands, &command{
flagSet: codeintelUploadFlagSet,
Expand All @@ -61,24 +57,13 @@ Examples:
fmt.Println(usage)
},
})

// Make 'upload' available under 'src lsif' for backwards compatibility.
lsifCommands = append(lsifCommands, &command{
flagSet: codeintelUploadFlagSet,
handler: handleCodeIntelUpload,
usageFunc: func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src lsif %s':\n", codeintelUploadFlagSet.Name())
codeintelUploadFlagSet.PrintDefaults()
fmt.Println(usage)
},
})
Comment on lines -65 to -74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to look into how src-cli docs are generated for the docs.sourcegraph.com page and regenerate those.

I found multiple copies of the file, one in the monorepo and one in the docs repo.

https://sourcegraph.sourcegraph.com/search?q=file:cli/references/code-intel/upload&patternType=keyword&sm=0

Not sure which is the source of truth.

}

// handleCodeIntelUpload is the handler for `src code-intel upload`.
func handleCodeIntelUpload(args []string) error {
ctx := context.Background()

out, isSCIPAvailable, err := parseAndValidateCodeIntelUploadFlags(args)
out, err := parseAndValidateCodeIntelUploadFlags(args)
if !codeintelUploadFlags.json {
if out != nil {
printInferredArguments(out)
Expand All @@ -96,7 +81,7 @@ func handleCodeIntelUpload(args []string) error {
Flags: codeintelUploadFlags.apiFlags,
})

uploadOptions := codeintelUploadOptions(out, isSCIPAvailable)
uploadOptions := codeintelUploadOptions(out)
uploadID, err := upload.UploadIndex(ctx, codeintelUploadFlags.file, client, uploadOptions)
if err != nil {
return handleUploadError(uploadOptions.SourcegraphInstanceOptions.AccessToken, err)
Expand Down Expand Up @@ -141,18 +126,13 @@ func handleCodeIntelUpload(args []string) error {
}

// codeintelUploadOptions creates a set of upload options given the values in the flags.
func codeintelUploadOptions(out *output.Output, isSCIPAvailable bool) upload.UploadOptions {
func codeintelUploadOptions(out *output.Output) upload.UploadOptions {
var associatedIndexID *int
if codeintelUploadFlags.associatedIndexID != -1 {
associatedIndexID = &codeintelUploadFlags.associatedIndexID
}

cfg.AdditionalHeaders["Content-Type"] = "application/x-ndjson+lsif"
path := codeintelUploadFlags.uploadRoute
if isSCIPAvailable && filepath.Ext(codeintelUploadFlags.file) == ".scip" {
cfg.AdditionalHeaders["Content-Type"] = "application/x-protobuf+scip"
path = strings.ReplaceAll(path, "lsif", "scip")
}
cfg.AdditionalHeaders["Content-Type"] = "application/x-protobuf+scip"

logger := upload.NewRequestLogger(
os.Stdout,
Expand All @@ -178,7 +158,7 @@ func codeintelUploadOptions(out *output.Output, isSCIPAvailable bool) upload.Upl
AdditionalHeaders: cfg.AdditionalHeaders,
MaxRetries: 5,
RetryInterval: time.Second,
Path: path,
Path: codeintelUploadFlags.uploadRoute,
MaxPayloadSizeBytes: codeintelUploadFlags.maxPayloadSizeMb * 1000 * 1000,
MaxConcurrency: codeintelUploadFlags.maxConcurrency,
GitHubToken: codeintelUploadFlags.gitHubToken,
Expand Down Expand Up @@ -263,7 +243,7 @@ func attachHintsForAuthorizationError(accessToken string, originalError error) e

if likelyTokenError {
return errorWithHint{err: originalError, hint: strings.Join(mergeStringSlices(
[]string{"A Sourcegraph access token must be provided via SRC_ACCESS_TOKEN for uploading SCIP/LSIF data."},
[]string{"A Sourcegraph access token must be provided via SRC_ACCESS_TOKEN for uploading SCIP data."},
actionableHints,
[]string{"For more details, see https://sourcegraph.com/docs/cli/how-tos/creating_an_access_token."},
), "\n")}
Expand Down Expand Up @@ -304,7 +284,7 @@ func attachHintsForAuthorizationError(accessToken string, originalError error) e
}

return errorWithHint{err: originalError, hint: strings.Join(mergeStringSlices(
[]string{"This Sourcegraph instance has enforced auth for SCIP/LSIF uploads."},
[]string{"This Sourcegraph instance has enforced auth for SCIP uploads."},
actionableHints,
[]string{"For more details, see https://docs.sourcegraph.com/cli/references/code-intel/upload."},
), "\n")}
Expand Down
Loading
Loading