diff --git a/server/cmd/lsp/args.go b/server/cmd/lsp/args.go index 62eead6..0e17297 100644 --- a/server/cmd/lsp/args.go +++ b/server/cmd/lsp/args.go @@ -6,6 +6,7 @@ import ( "runtime/debug" "time" + "github.com/pherrymason/c3-lsp/internal/c3c" "github.com/pherrymason/c3-lsp/internal/lsp/server" "github.com/pherrymason/c3-lsp/pkg/option" ) @@ -47,10 +48,11 @@ func cmdLineArguments() (server.ServerOpts, bool, bool) { //log.Printf("---------------") return server.ServerOpts{ - C3: server.C3Opts{ - Version: option.None[string](), - Path: c3cPathOpt, - StdlibPath: stdlibPathOpt, + C3: c3c.C3Opts{ + Version: option.None[string](), + Path: c3cPathOpt, + StdlibPath: stdlibPathOpt, + CompileArgs: []string{}, }, Diagnostics: server.DiagnosticsOpts{ Delay: time.Duration(*diagnosticsDelay), diff --git a/server/internal/c3c/c3c.go b/server/internal/c3c/c3c.go index 3250adc..c5d70ff 100644 --- a/server/internal/c3c/c3c.go +++ b/server/internal/c3c/c3c.go @@ -45,9 +45,16 @@ func GetC3Version(c3Path option.Option[string]) option.Option[string] { return option.None[string]() } -func CheckC3ErrorsCommand(c3Path option.Option[string], projectPath string) (bytes.Buffer, bytes.Buffer, error) { - binary := binaryPath(c3Path) - command := exec.Command(binary, "build", "--test") +func CheckC3ErrorsCommand(c3Options C3Opts, projectPath string) (bytes.Buffer, bytes.Buffer, error) { + binary := binaryPath(c3Options.Path) + + args := []string{"build", "--test"} + if len(c3Options.CompileArgs) > 0 { + args = append(args, c3Options.CompileArgs...) + } + log.Printf("C3C arguments used:", args) + + command := exec.Command(binary, args...) command.Dir = projectPath // set var to get the output diff --git a/server/internal/c3c/options.go b/server/internal/c3c/options.go new file mode 100644 index 0000000..510f205 --- /dev/null +++ b/server/internal/c3c/options.go @@ -0,0 +1,10 @@ +package c3c + +import "github.com/pherrymason/c3-lsp/pkg/option" + +type C3Opts struct { + Version option.Option[string] `json:"version"` + Path option.Option[string] `json:"path"` + StdlibPath option.Option[string] `json:"stdlib-path"` + CompileArgs []string `json:"compile-args"` +} diff --git a/server/internal/lsp/server/Diagnostics.go b/server/internal/lsp/server/Diagnostics.go index c67c37a..ca92a82 100644 --- a/server/internal/lsp/server/Diagnostics.go +++ b/server/internal/lsp/server/Diagnostics.go @@ -19,7 +19,7 @@ func (s *Server) RunDiagnostics(state *project_state.ProjectState, notify glsp.N } runDiagnostics := func() { - out, stdErr, err := c3c.CheckC3ErrorsCommand(s.options.C3.Path, state.GetProjectRootURI()) + out, stdErr, err := c3c.CheckC3ErrorsCommand(s.options.C3, state.GetProjectRootURI()) log.Println("output:", out.String()) log.Println("output:", stdErr.String()) if err == nil { diff --git a/server/internal/lsp/server/config.go b/server/internal/lsp/server/config.go index d95a8b6..a4caafe 100644 --- a/server/internal/lsp/server/config.go +++ b/server/internal/lsp/server/config.go @@ -11,12 +11,6 @@ import ( "github.com/pherrymason/c3-lsp/pkg/option" ) -type C3Opts struct { - Version option.Option[string] `json:"version"` - Path option.Option[string] `json:"path"` - StdlibPath option.Option[string] `json:"stdlib-path"` -} - type DiagnosticsOpts struct { Enabled bool `json:"enabled"` Delay time.Duration `json:"delay"` @@ -24,7 +18,7 @@ type DiagnosticsOpts struct { // ServerOpts holds the options to create a new Server. type ServerOpts struct { - C3 C3Opts `json:"C3Opts"` + C3 c3c.C3Opts `json:"C3Opts"` Diagnostics DiagnosticsOpts `json:"Diagnostics"` LogFilepath option.Option[string] @@ -34,9 +28,10 @@ type ServerOpts struct { type ServerOptsJson struct { C3 struct { - Version *string `json:"version,omitempty"` - Path *string `json:"path,omitempty"` - StdlibPath *string `json:"stdlib-path,omitempty"` + Version *string `json:"version,omitempty"` + Path *string `json:"path,omitempty"` + StdlibPath *string `json:"stdlib-path,omitempty"` + CompileArgs []string `json:"compile-args"` } Diagnostics struct { @@ -78,11 +73,16 @@ func (s *Server) loadServerConfigurationForWorkspace(path string) { if options.C3.Version != nil { s.options.C3.Version = option.Some(*options.C3.Version) } + if options.C3.Path != nil { s.options.C3.Path = option.Some(*options.C3.Path) // Get version from binary } + if len(options.C3.CompileArgs) > 0 { + s.options.C3.CompileArgs = options.C3.CompileArgs + } + c3Version := c3c.GetC3Version(s.options.C3.Path) if c3Version.IsSome() { s.options.C3.Version = c3Version