github.com/tiagovtristao/plz@v13.4.0+incompatible/tools/build_langserver/lsp/initialize.go (about)

     1  package lsp
     2  
     3  import (
     4  	"errors"
     5  	"gopkg.in/op/go-logging.v1"
     6  	"strings"
     7  )
     8  
     9  var log = logging.MustGetLogger("lsp")
    10  
    11  /**
    12   * Initialze.go defines all structs to do with initialize method
    13   *
    14   * method: 'initialize'
    15   * params: InitializeParams
    16   *
    17   */
    18  
    19  // InitializeParams are params passed into `initialize` method request
    20  type InitializeParams struct {
    21  	/**
    22  	 * The process Id of the parent process that started
    23  	 * the server. Is null if the process has not been started by another process.
    24  	 * If the parent process is not alive then the server should exit (see exit notification) its process.
    25  	 */
    26  	ProcessID int `json:"processId,omitempty"`
    27  
    28  	/**
    29  	 * @deprecated in favour of rootUri.
    30  	 * having it here in case some lsp client still uses this field
    31  	 */
    32  	RootPath string `json:"rootPath,omitempty"`
    33  
    34  	/**
    35  	 * The rootUri of the workspace. Is null if no
    36  	 * folder is open. If both `rootPath` and `rootUri` are set
    37  	 * `rootUri` wins.
    38  	 */
    39  	RootURI DocumentURI `json:"rootUri,omitempty"`
    40  
    41  	/**
    42  	 * User provided initialization options.
    43  	 */
    44  	InitializationOptions interface{} `json:"initializationOptions,omitempty"`
    45  
    46  	/**
    47  	 * The capabilities provided by the client (editor or tool)
    48  	 */
    49  	Capabilities ClientCapabilities `json:"capabilities"`
    50  
    51  	/**
    52  	 * The workspace folders configured in the client when the server starts.
    53  	 * This property is only available if the client supports workspace folders.
    54  	 * It can be `null` if the client supports workspace folders but none are
    55  	 * configured.
    56  	 */
    57  	WorkspaceFolders []WorkspaceFolder `json:"workspaceFolders,omitempty"`
    58  }
    59  
    60  // Root returns the RootURI if set, or otherwise the RootPath with 'file://' prepended.
    61  func (p *InitializeParams) Root() DocumentURI {
    62  	if p.RootURI != "" {
    63  		return p.RootURI
    64  	}
    65  	if strings.HasPrefix(p.RootPath, "file://") {
    66  		return DocumentURI(p.RootPath)
    67  	}
    68  
    69  	return DocumentURI("file://" + p.RootPath)
    70  }
    71  
    72  // EnsureRoot sets the RootURI of the Intialization if not Set
    73  func (p *InitializeParams) EnsureRoot() error {
    74  	if p.RootPath == "" && p.RootURI == "" {
    75  		return errors.New("rootPath and rootURI cannot be both empty")
    76  	}
    77  
    78  	// When RootPath is not empty, remote the URI part for RootPath
    79  	if strings.HasPrefix(p.RootPath, "file://") {
    80  		log.Info("Passing an initialize rootPath URI (%q) is deprecated. Use rootUri instead.", p.RootPath)
    81  		p.RootPath = strings.TrimPrefix(p.RootPath, "file://")
    82  	} else {
    83  		// at this point rootURL should not be empty
    84  		p.RootPath = strings.TrimPrefix(string(p.RootURI), "file://")
    85  	}
    86  
    87  	// Ensure RootURL is in URL format with prefix `file://`
    88  	p.RootURI = p.Root()
    89  
    90  	return nil
    91  }
    92  
    93  // InitializeResult is the response server sends to the client from "initialize" method
    94  type InitializeResult struct {
    95  	/**
    96  	 * The capabilities the language server provides.
    97  	 */
    98  	Capabilities ServerCapabilities `json:"capabilities"`
    99  }
   100  
   101  //InitializeError are known error code
   102  type InitializeError struct {
   103  	/**
   104  	 * Indicates whether the client execute the following retry logic:
   105  	 * (1) show the message provided by the ResponseError to the user
   106  	 * (2) user selects retry or cancel
   107  	 * (3) if user selected retry the initialize method is sent again.
   108  	 */
   109  	Retry bool `json:"retry"`
   110  }
   111  
   112  // ClientCapabilities represents the capability of a client editor
   113  type ClientCapabilities struct {
   114  	/**
   115  	 * Workspace specific client capabilities.
   116  	 */
   117  	Workspace WorkspaceClientCapabilities `json:"workspace,omitempty"`
   118  
   119  	/**
   120  	 * Text document specific client capabilities.
   121  	 */
   122  	TextDocument TextDocumentClientCapabilities `json:"textDocument,omitempty"`
   123  
   124  	/**
   125  	 * Experimental client capabilities.
   126  	 */
   127  	Experimental interface{} `json:"experimental,omitempty"`
   128  }