Skip to content

Commit

Permalink
Merge pull request #57 from pherrymason/error-diagnostics
Browse files Browse the repository at this point in the history
Reporting error diagnostics by using `c3c build --test`
  • Loading branch information
pherrymason authored Aug 27, 2024
2 parents 3b90414 + c232713 commit 3065181
Show file tree
Hide file tree
Showing 23 changed files with 329 additions and 180 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.configureOnOpen": false
}
8 changes: 8 additions & 0 deletions client/vscode/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ module.exports = {
args.push('--lang-version '+config.get('c3.version'));
}

if (config.get('c3.path')) {
args.push('--c3c-path '+config.get('c3.path'));
}

if (config.get('diagnosticsDelay')) {
args.push('--diagnostics-delay '+config.get('diagnosticsDelay'));
}

const serverOptions = {
run: {
command: executable,
Expand Down
12 changes: 11 additions & 1 deletion client/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "c3-lsp-client",
"displayName": "C3 Language Server client",
"description": "Language Server client for C3. Download C3 server from https://github.com/pherrymason/c3-lsp",
"version": "0.0.3",
"version": "0.1.0",
"publisher": "rferras",
"engines": {
"vscode": "^1.40.0"
Expand Down Expand Up @@ -54,10 +54,20 @@
"default": false,
"markdownDescription": "Sends crash reports to server to help fixing bugs."
},
"c3lspclient.lsp.diagnosticsDelay": {
"type": "integer",
"default": 2000,
"markdownDescription": "Delay calculation of code diagnostics after modifications in source. In milliseconds, default 2000 ms."
},
"c3lspclient.lsp.c3.version": {
"type": "string",
"default": null,
"markdownDescription": "Specify C3 language version. If omited, LSP will use the last version it supports."
},
"c3lspclient.lsp.c3.path": {
"type": "string",
"default": null,
"markdownDescription": "Path to C3C binary. Use it if not defined already in your PATH environment variable or if you want to use a different one."
}
}
}
Expand Down
75 changes: 75 additions & 0 deletions server/cmd/lsp/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"flag"
"fmt"
"runtime/debug"
"time"

"github.com/pherrymason/c3-lsp/internal/lsp/server"
"github.com/pherrymason/c3-lsp/pkg/option"
)

func cmdLineArguments() (server.ServerOpts, bool) {
var showHelp = flag.Bool("help", false, "Shows this help")
var sendCrashReports = flag.Bool("send-crash-reports", false, "Automatically reports crashes to server.")

var logFilePath = flag.String("log-path", "", "Enables logs and sets its filepath")
var debug = flag.Bool("debug", false, "Enables debug mode")

var c3Version = flag.String("lang-version", "", "Specify C3 language version.")
var c3cPath = flag.String("c3c-path", "", "Path where c3c is located.")
var diagnosticsDelay = flag.Int("diagnostics-delay", 2000, "Delay calculation of code diagnostics after modifications in source. In milliseconds, default 2000 ms.")

flag.Parse()

c3VersionOpt := option.None[string]()
if *c3Version != "" {
c3VersionOpt = option.Some(*c3Version)
}
c3cPathOpt := option.None[string]()
if *c3cPath != "" {
c3cPathOpt = option.Some(*c3cPath)
}
logFilePathOpt := option.None[string]()
if *logFilePath != "" {
logFilePathOpt = option.Some(*logFilePath)
}

return server.ServerOpts{
C3Version: c3VersionOpt,
C3CPath: c3cPathOpt,
DiagnosticsDelay: time.Duration(*diagnosticsDelay),
DiagnosticsEnabled: true,
LogFilepath: logFilePathOpt,
Debug: *debug,
SendCrashReports: *sendCrashReports,
}, *showHelp
}

func printAppGreet(appName string, version string, commit string) {
fmt.Printf("%s version %s (%s)\n", appName, version, commit)
}

func printHelp(appName string, version string, commit string) {
printAppGreet(appName, version, commit)

fmt.Println("\nOptions")
flag.PrintDefaults()
}

func buildInfo() string {
var Commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}

return ""
}()

return Commit
}
90 changes: 7 additions & 83 deletions server/cmd/lsp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ package main
import (
"fmt"
"log"
"runtime/debug"
"time"

"github.com/getsentry/sentry-go"
"github.com/pherrymason/c3-lsp/internal/lsp"
"github.com/pherrymason/c3-lsp/pkg/option"
flag "github.com/spf13/pflag"
"github.com/pherrymason/c3-lsp/internal/lsp/server"
)

const version = "0.1.1"
const prerelease = false
const version = "0.2.0"
const prerelease = true
const appName = "C3-LSP"

func getVersion() string {
Expand All @@ -25,15 +22,15 @@ func getVersion() string {
}

func main() {
options := cmdLineArguments()
options, showHelp := cmdLineArguments()
commitHash := buildInfo()
if options.showHelp {
if showHelp {
printHelp(appName, getVersion(), commitHash)

return
}

if options.sendCrashReports {
if options.SendCrashReports {
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/4507278372110336",
Release: fmt.Sprintf("c3.lsp@%s+%s", getVersion(), commitHash),
Expand All @@ -49,79 +46,6 @@ func main() {
defer sentry.Recover()
}

c3Version := option.None[string]()
if options.c3Version != "" {
c3Version = option.Some(options.c3Version)
}

logFilePath := option.None[string]()
if options.logFilePath != "" {
logFilePath = option.Some(options.logFilePath)
}

server := lsp.NewServer(lsp.ServerOpts{
Name: appName,
Version: version,
C3Version: c3Version,
LogFilepath: logFilePath,
SendCrashReports: options.sendCrashReports,
Debug: options.debug,
})
server := server.NewServer(options, appName, version)
server.Run()
}

type Options struct {
showHelp bool
c3Version string
logFilePath string
debug bool
sendCrashReports bool
}

func cmdLineArguments() Options {
var showHelp = flag.Bool("help", false, "Shows this help")

var sendCrashReports = flag.Bool("send-crash-reports", false, "Automatically reports crashes to server.")

var logFilePath = flag.String("log-path", "", "Enables logs and sets its filepath")
var debug = flag.Bool("debug", false, "Enables debug mode")

var c3Version = flag.String("lang-version", "", "Specify C3 language version.")

flag.Parse()

return Options{
showHelp: *showHelp,
c3Version: *c3Version,
logFilePath: *logFilePath,
debug: *debug,
sendCrashReports: *sendCrashReports,
}
}

func printAppGreet(appName string, version string, commit string) {
fmt.Printf("%s version %s (%s)\n", appName, version, commit)
}

func printHelp(appName string, version string, commit string) {
printAppGreet(appName, version, commit)

fmt.Println("\nOptions")
flag.PrintDefaults()
}

func buildInfo() string {
var Commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}

return ""
}()

return Commit
}
2 changes: 2 additions & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ require (

require golang.org/x/mod v0.20.0

require github.com/bep/debounce v1.2.1 // indirect

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/dave/jennifer v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/dave/jennifer v1.7.0 h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=
github.com/dave/jennifer v1.7.0/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
11 changes: 0 additions & 11 deletions server/internal/lsp/handlers/TextDocumentDidChange.go

This file was deleted.

11 changes: 0 additions & 11 deletions server/internal/lsp/handlers/TextDocumentDidSave.go

This file was deleted.

21 changes: 0 additions & 21 deletions server/internal/lsp/handlers/handlers.go

This file was deleted.

Loading

0 comments on commit 3065181

Please sign in to comment.