pkg

package
v0.0.0-...-2491a15 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Database operations

Index

Constants

View Source
const (
	// Pragmas are used to initialize an in-memory database. Useful for tests.
	Pragmas = `?cache=shared&mode=memory`
	// For the time being, use an in-memory database.
	DefaultFilename = `file:test.db` + Pragmas
	// This socket name causes using stdin/stdout instead of a specific unix
	// domain socket.
	DefaultSocket = `:stdstream:`
)
View Source
const (
	// SqliteDriver is the name of the used SQL driver module.
	SqliteDriver = `sqlite3`

	InsertDeltaStatementStr = `
		BEGIN TRANSACTION;

		UPDATE TABLE	AnnotationLocations
		SET				Line = Line + ?
		WHERE			File = ? AND Line > ?

		COMMIT;`
)
View Source
const (
	PccSetCmd = `$/pcc/set`
	PccGetCmd = `$/pcc/get`
	CancelCmd = `%/cancelRequest`
)
View Source
const ConfigFilename = `pcc.config.json`

ConfigFilename is the file name that, if found in the workspace, is used to name the workspace.

Variables

View Source
var ExitError = fmt.Errorf("exiting")

Functions

func BulkDeleteAnn

func BulkDeleteAnn(db *sql.DB, workspace, path string, firstLine uint32, lastLine uint32, delta int32) error

BulkDeleteAnn bulk-deletes annotations.

func BulkMoveAnn

func BulkMoveAnn(db *sql.DB, workspace, path string, firstLine uint32, delta int32) error

BulkMoveAnn moves annotation locations starting from given line to EOF by 'delta'.

Note: firstLine is zero-indexed.

func CreateDBFile

func CreateDBFile(dbFilename string) (bool, error)

CreateDBFile creates an empty database file at the given name.

Returns true if the database needs to be initialized, e.g. if an empty file without a schema was created.

func CreateDBSchema

func CreateDBSchema(db *sql.DB) error

CreateDBSchema creates the data schema used in this program in an empty database db.

func CreateSchema

func CreateSchema(db *sql.DB) error

CreateSchema creates the database with the appropriate file pkg.

func DeleteAnn

func DeleteAnn(db *sql.DB, workspace, path string, line uint32) error

DeleteAnn deletes an annotation for the specific workspace, path and line. The annotation does not need to exist.

func FindWorkspace

func FindWorkspace(w []lsp.WorkspaceFolder, fileURI lsp.URI) (string, string)

FindWorkspace findss the workspace that the file with uri URI belongs to. Returns the workspace URI encoded as string, and the relative path for the provided file.

Example:

For a workspace "file:///ws/file.txt", returns:
("file:///ws", "/file.txt")

func GetAnn

func GetAnn(db *sql.DB, workspace, path string, line uint32) (string, error)

GetAnn retrieves a single annotation. Or an error if that particular annotation does not exist.

func InsertAnn

func InsertAnn(db *sql.DB, workspace, path string, line uint32, text string) error

InsertAnn inserts an annotation into the database. The annotation line must not previously exist.

Args:

  • workspace: the workspace, either an URI or a symbolic prefix.
  • path: the file path relative to the workspace. For example, for ws="file://dir", and file URI "file://dir/file.txt", then path should be "/file.txt".

func JSONUnmarshal

func JSONUnmarshal[T any](r io.Reader) (T, error)

JSONUnmarshal is a typed parser for a go type.

func MakeAllDirs

func MakeAllDirs(filename string) error

MakeAllDirs makes all the directories on the path of the *file* named in the parameter.

func MakeDiagnostic

func MakeDiagnostic(lr LineRange, m string) lsp.Diagnostic

MakeDiagnostic creates a single diagnostic line.

func MoveAnn

func MoveAnn(db *sql.DB, workspace, path string, line uint32, newPath string, newLine uint32) error

MoveAnn moves a single annotation from a file location to another location in a possibly different file.

func RPath

func RPath(ws string, fileURI lsp.URI) string

RPath returns a file path relative to the given workspace. ws is the string representation of a workspace URI, e.g. "file:///ws" fileURI is the an URI possibly in that workspace, like "file:///ws/file.txt" In this case we'll be returning "/file.txt", i.e. a path rooted in `ws`.

func ResolveWs

func ResolveWs(in []lsp.WorkspaceFolder) []lsp.WorkspaceFolder

ResolveWs resolves the workspace names, potentially using the marker config filename to get the workspace name.

For a workspace: "file:///ws/file.txt" and a workspace name mapping: "file:///ws" -> "ws" returns:

("ws", "/file.txt")

func TxBulkAppendAnn

func TxBulkAppendAnn(tx *sql.Tx, workspace, path string, firstline, lastline uint32, delta int32) error

TxBulkAppendAnn schedules an append in order of all the annotations on the file path between firstline and lastline in the appropriate sequence.

func TxBulkMoveAnn

func TxBulkMoveAnn(tx *sql.Tx, workspace, path string, firstLine uint32, delta int32) error

TxBulkMoveAnn schedules a BulkMoveAnn into a transaction.

Types

type Ann

type Ann struct {
	// Line is the 0-based line index of the line where the annotation is.
	Line uint32
	// Content is the string content of the annotation.
	Content string
}

A single annotation

func GetAnns

func GetAnns(db *sql.DB, workspace, path string) ([]Ann, error)

GetAnns returns all annotations for the given path in the workspace.

func GetRawAnns

func GetRawAnns(db *sql.DB) ([]Ann, error)

GetRawAnns gets all the annotations from the database.

type DiagnosticMsg

type DiagnosticMsg struct {
	// The URI of the file to refresh.
	URI lsp.URI

	// If set, the diagnostics are always updated. When unset, the Diagnostic
	// update is allowed to skip some updates.
	Force bool
}

DiagnosticMsg contains the message sent to the diagnostic hander.

type LineRange

type LineRange struct {
	// Start is zero based.
	Start uint32
	// End is zero based.
	End              uint32
	StartCol, EndCol uint32
}

func NewLineRange

func NewLineRange(r lsp.Range) LineRange

NewLineRange creates a unified LineRange from equivalent LSP type.

func (LineRange) NumLines

func (l LineRange) NumLines() uint32

NumLines returns the number of lines spanned by this line range.

type PccGet

type PccGet struct {
	File lsp.URI `json:"file"`
	Line uint32  `json:"line"`
}

type PccGetResp

type PccGetResp struct {
	Content []string `json:"content"`
}

type PccSet

type PccSet struct {
	PccGet
	Content []string `json:"content"`
}

type PccSetRes

type PccSetRes struct{}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, db *sql.DB, conn jsonrpc2.Conn) (*Server, error)

func (*Server) DiagnosticsFn

func (s *Server) DiagnosticsFn()

func (*Server) FindWorkspace

func (s *Server) FindWorkspace(fileURI lsp.URI) (string, string)

Finds the workspace that the file with uri URI belongs to. Returns the workspace URI encoded as string, and the relative path for the provided file.

func (*Server) GetHandlerFunc

func (s *Server) GetHandlerFunc() jsonrpc2.Handler

GetHandlerFunc returns a stateful function that can be given to jsonrpc2.StreamServer to serve JSON-RPC2 requests.

func (*Server) MoveAnnotations

func (s *Server) MoveAnnotations(ctx context.Context, lr LineRange, delta int32, uri lsp.URI) error

INVARIANT: delta != 0.

func (*Server) Shutdown

func (s *Server) Shutdown()

type WorkspaceConfig

type WorkspaceConfig struct {
	WorkspaceName string `json:"workspace_name,omitempty"`
}

Config file is put into the workspace.

Jump to

Keyboard shortcuts

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