clicmds

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2023 License: MIT Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SeverityHigh = iota
	SeverityMedium
	SeverityLow
)
View Source
const (
	DocumentOpen = iota
	DocumentSave
	DocumentChange
)
View Source
const (
	LangSrvNameParamName  = "name"
	LangSrvNameEnvVarName = "LANGSRV_NAME"

	LangSrvHostParamName  = "host"
	LangSrvHostEnvVarName = "LANGSRV_HOST"

	LangSrvSrcDirParamName  = "srcdir"
	LangSrvSrcDirEnvVarName = "LANGSRV_SRC_DIR"

	LangSrvGitLabApiTokenParamName  = "gitlab-api-token"
	LangSrvGitLabApiTokenEnvVarName = "LANGSRV_GITLAB_API_TOKEN"

	LangSrvPortParamName  = "port"
	LangSrvPortEnvVarName = "LANGSRV_PORT"
)

Variables

View Source
var ErrInvalidAccessToken = errors.New("invalid GitLab access token")

ErrInvalidAccessToken is returned by [WriteAccessToken] if token does not look like a valid GitLab access token.

Functions

func Max

func Max[T protocol.UInteger | int](a, b T) T

func Min

func Min[T protocol.UInteger | int](a, b T) T

func Overlap

func Overlap(rangea, rangeb protocol.Range) bool

func RunGitlabTokenRegister added in v0.4.0

func RunGitlabTokenRegister(_ *cli.Context) error

func RunServe

func RunServe(cli *cli.Context) error

func ServeFlags

func ServeFlags() []cli.Flag

func WriteGitlabAccessToken added in v0.4.0

func WriteGitlabAccessToken(token string) error

WriteGitlabAccessToken to a file inside current user's configuration directory.

If the `LANGSRV_GITLAB_API_TOKEN_FILE` environment variable it set, it will use that as file path for the access token file.

Types

type CodeDiagnostic

type CodeDiagnostic struct {
	Origin,
	Message,
	File string // the file that contains the issue
	Severity   Severity   // severity of the issue (most IDEs will provide color codes)
	Coordinate Coordinate // source code coordiates of the issue
	Fix        *CodeFix   // Fix (Optional)
}

CodeDiagnostic objects are useful to highlight issues in the IDE. If you know how to fix an issue, yo can provide a Fix with the Diagnostic.

func (*CodeDiagnostic) ToCodeAction

func (feedback *CodeDiagnostic) ToCodeAction() protocol.CodeAction

func (*CodeDiagnostic) ToLspDiagnostic

func (feedback *CodeDiagnostic) ToLspDiagnostic() protocol.Diagnostic

type CodeFix

type CodeFix struct {
	Hint        string // A small description to describe the fix.
	Replacement string // The actual replacement for the code captured by the Diagnostic.
}

CodeFix describes a fix for a given issue and is, hence, always attached to a CodeDiagnostic object.

type CodeSuggesion

type CodeSuggesion struct {
	Label       string
	Content     string
	Description string
}

CodeSuggesion objects are useful to provide code suggestions in the IDE. Most IDEs will provide a drop-down menu from which the user can make a selection.

func NewCodeSuggestion

func NewCodeSuggestion(label, content, description string) *CodeSuggesion

func (*CodeSuggesion) ToCompletionItem

func (s *CodeSuggesion) ToCompletionItem() protocol.CompletionItem

type Coordinate

type Coordinate struct {
	StartLine, EndLine, StartCol, EndCol int
}

Coordinate describes the position of a finding

type CursorContext added in v0.3.0

type CursorContext struct {
	Before, After string
}

CursorContext defines the text before and after the cursors the window width

func (*CursorContext) Empty added in v0.3.0

func (c *CursorContext) Empty() bool

func (*CursorContext) String added in v0.3.0

func (c *CursorContext) String() string

type DocumentAction

type DocumentAction int

type FeedBackProvider

type FeedBackProvider interface {
	// ProvideDiagnosticsForFile is a callback to pass diagnostics to the
	// language server. The results will be highlighted in the IDE.
	ProvideDiagnosticsForFile(file string, action DocumentAction) ([]*CodeDiagnostic, error)
	// ProvideDiagnosticsForContent is identical to
	// ProvideDiagnosticsForFile with the only difference that it runs on
	// the content and captures in-memory change.
	ProvideDiagnosticsForContent(filePath, content string, action DocumentAction) ([]*CodeDiagnostic, error)
	ProvideCodeSuggesions(filePath string, context *CursorContext) ([]*CodeSuggesion, error)
}

FeedBackProvider is the (only) interface new language servers have to implement.

type LspServer

type LspServer struct {
	Configuration    *LspServerConfiguration
	Actions          []protocol.CodeAction
	FeedbackProvider map[string]FeedBackProvider
	CursorContext    *CursorContext
	DocumentCache    *ristretto.Cache
}

func NewLspServer

func NewLspServer(cfg *LspServerConfiguration) *LspServer

func (*LspServer) AddFeedbackProvider

func (l *LspServer) AddFeedbackProvider(name string, provider FeedBackProvider)

func (*LspServer) CodeActionReset

func (s *LspServer) CodeActionReset()

func (*LspServer) Start

func (s *LspServer) Start() error

func (*LspServer) UpdateCursorContext added in v0.3.0

func (l *LspServer) UpdateCursorContext(doc protocol.DocumentUri, pos protocol.Position) error

type LspServerConfiguration

type LspServerConfiguration struct {
	Stdio                                                 bool
	SrcDir, Token, Name, Url                              string
	Port, CursorWindowWidthBefore, CursorWindowWidthAfter uint
}

func NewLspServerConfiguration

func NewLspServerConfiguration(name, srcDir, url, token string, cursorBefore, cursorAfter, port uint) (*LspServerConfiguration, error)

func (*LspServerConfiguration) ServerUrl

func (cfg *LspServerConfiguration) ServerUrl() string

func (*LspServerConfiguration) String

func (cfg *LspServerConfiguration) String() string

type Severity

type Severity int

func (Severity) ToLspSeverity

func (severity Severity) ToLspSeverity() protocol.DiagnosticSeverity

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL