This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for monikers using go.mod and go.sum files.
- Loading branch information
Showing
15 changed files
with
578 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ | |
/.vscode | ||
/.idea | ||
/lsif-go | ||
/lsif-gomod | ||
/data.lsif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// The program lsif-go is an LSIF exporter for Go. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"time" | ||
|
||
"github.com/alecthomas/kingpin" | ||
"github.com/sourcegraph/lsif-go/export" | ||
"github.com/sourcegraph/lsif-go/log" | ||
"github.com/sourcegraph/lsif-go/protocol" | ||
) | ||
|
||
const version = "0.4.1" | ||
const versionString = version + ", protocol version " + protocol.Version | ||
|
||
func main() { | ||
if err := realMain(); err != nil { | ||
fmt.Fprint(os.Stderr, fmt.Sprintf("error: %v\n", err)) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func realMain() error { | ||
var ( | ||
debug bool | ||
verbose bool | ||
projectRoot string | ||
noContents bool | ||
outFile string | ||
stdout bool | ||
) | ||
|
||
app := kingpin.New("lsif-go", "lsif-go is an LSIF exporter for Go.").Version(versionString) | ||
app.Flag("debug", "Display debug information.").Default("false").BoolVar(&debug) | ||
app.Flag("verbose", "Display verbose information.").Short('v').Default("false").BoolVar(&verbose) | ||
app.Flag("projectRoot", "Specifies the project root. Defaults to the current working directory.").Default(".").StringVar(&projectRoot) | ||
app.Flag("noContents", "File contents will not be embedded into the dump.").Default("false").BoolVar(&noContents) | ||
app.Flag("out", "The output file the dump is save to.").StringVar(&outFile) | ||
app.Flag("stdout", "Writes the dump to stdout.").Default("false").BoolVar(&stdout) | ||
|
||
_, err := app.Parse(os.Args[1:]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if outFile == "" && !stdout { | ||
return fmt.Errorf("either an output file using --out or --stdout must be specified") | ||
} | ||
|
||
if debug { | ||
log.SetLevel(log.Debug) | ||
} | ||
|
||
if verbose { | ||
log.SetLevel(log.Info) | ||
} | ||
|
||
if stdout && (verbose || debug) { | ||
return fmt.Errorf("debug and verbose options cannot be enabled with --stdout") | ||
} | ||
|
||
start := time.Now() | ||
|
||
var out io.Writer | ||
if stdout { | ||
out = os.Stdout | ||
} else { | ||
file, err := os.Create(outFile) | ||
if err != nil { | ||
return fmt.Errorf("create dump file: %v", err) | ||
} | ||
|
||
defer file.Close() | ||
out = file | ||
} | ||
|
||
s, err := export.Export( | ||
projectRoot, | ||
noContents, | ||
out, | ||
protocol.ToolInfo{ | ||
Name: "lsif-go", | ||
Version: version, | ||
Args: os.Args[1:], | ||
}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("export: %v", err) | ||
} | ||
|
||
if !stdout { | ||
log.Printf("%d package(s), %d file(s), %d def(s), %d element(s)", s.NumPkgs, s.NumFiles, s.NumDefs, s.NumElements) | ||
log.Println("Processed in", time.Since(start)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// The program lsif-gomod adds gomod moniker support to lsif-go output. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/alecthomas/kingpin" | ||
"github.com/sourcegraph/lsif-go/gomod" | ||
"github.com/sourcegraph/lsif-go/protocol" | ||
) | ||
|
||
const version = "0.4.1" | ||
const versionString = version + ", protocol version " + protocol.Version | ||
|
||
func main() { | ||
if err := realMain(); err != nil { | ||
fmt.Fprint(os.Stderr, fmt.Sprintf("error: %v\n", err)) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func realMain() error { | ||
var ( | ||
projectRoot string | ||
inFile string | ||
stdin bool | ||
outFile string | ||
stdout bool | ||
) | ||
|
||
app := kingpin.New("lsif-gomod", "lsif-gomod decorates lsif-go output with gomod monikers.").Version(versionString) | ||
app.Flag("projectRoot", "Specifies the project root. Defaults to the current working directory.").Default(".").StringVar(&projectRoot) | ||
app.Flag("in", "Specifies the file that contains a LSIF dump.").StringVar(&inFile) | ||
app.Flag("stdin", "Reads the dump from stdin.").Default("false").BoolVar(&stdin) | ||
app.Flag("out", "The output file the converted dump is saved to.").StringVar(&outFile) | ||
app.Flag("stdout", "Writes the dump to stdout.").Default("false").BoolVar(&stdout) | ||
|
||
_, err := app.Parse(os.Args[1:]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if inFile == "" && !stdin { | ||
return fmt.Errorf("either an input file using --in or --stdin must be specified") | ||
} | ||
|
||
if outFile == "" && !stdout { | ||
return fmt.Errorf("either an output file using --out or --stdout must be specified") | ||
} | ||
|
||
var in io.Reader | ||
if stdin { | ||
in = os.Stdin | ||
} else { | ||
file, err := os.Open(inFile) | ||
if err != nil { | ||
return fmt.Errorf("open dump file: %v", err) | ||
} | ||
|
||
defer file.Close() | ||
in = file | ||
} | ||
|
||
var out io.Writer | ||
if stdout { | ||
out = os.Stdout | ||
} else { | ||
file, err := os.Create(outFile) | ||
if err != nil { | ||
return fmt.Errorf("create dump file: %v", err) | ||
} | ||
|
||
defer file.Close() | ||
out = file | ||
} | ||
|
||
return gomod.Decorate(in, out, projectRoot) | ||
} |
Oops, something went wrong.