-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tlin support for onSave requests (#10)
* feat: tlin support for onSave requests * feat: use the formatter library instead of CLI * feat: newv ersion of tlin * chore: remove toolchain different version of go * fix: correct line and column for lint diagnostics * feat: append lint diagnostics to others * refactor: remove useless args from getTranspileDiagnostics * feat: add logs when transpile or lint fails
- Loading branch information
1 parent
1ec8c8b
commit 5a36601
Showing
5 changed files
with
114 additions
and
45 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
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
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,44 @@ | ||
package tools | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gnolang/tlin/lint" | ||
"go.lsp.dev/jsonrpc2" | ||
"go.lsp.dev/protocol" | ||
) | ||
|
||
func Lint(ctx context.Context, conn jsonrpc2.Conn, text string, uri protocol.DocumentURI) ([]protocol.Diagnostic, error) { | ||
parsedText := []byte(text) | ||
|
||
engine, err := lint.New("", parsedText) | ||
if err != nil { | ||
return nil, err | ||
} | ||
issues, err := lint.ProcessSource(engine, parsedText) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// send the diagnostics | ||
diagnostics := make([]protocol.Diagnostic, len(issues)) | ||
for i, issue := range issues { | ||
diagnostics[i] = protocol.Diagnostic{ | ||
Range: protocol.Range{ | ||
Start: protocol.Position{ | ||
Line: uint32(issue.Start.Line - 1), | ||
Character: uint32(issue.Start.Column - 1), | ||
}, | ||
End: protocol.Position{ | ||
Line: uint32(issue.End.Line - 1), | ||
Character: uint32(issue.End.Column - 1), | ||
}, | ||
}, | ||
Severity: protocol.DiagnosticSeverityError, | ||
Code: issue.Rule, | ||
Message: issue.Message, | ||
Source: "gnopls", | ||
} | ||
} | ||
return diagnostics, nil | ||
} |