mirror of
https://github.com/golang/go
synced 2024-11-05 14:46:11 -07:00
internal/lsp: update code for LSP protocol
1. Change code.ts so it generates []json.RawMessage in place of []interface{} for Command-related arguments. As usual, vscode introduces a lot of whitespace-only changes. 2. Generate code based on the July 28 version of vscode-languageserver. The changes are mostly related to SemanticToken, and didn't require any changes to gopls, other than in the generated code. Change-Id: I673e29e2fbc097409683dfe7af911d8f66e25c5c Reviewed-on: https://go-review.googlesource.com/c/tools/+/245134 Run-TryBot: Peter Weinberger <pjw@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
55644ead90
commit
cd83430bb0
@ -2,8 +2,8 @@ package protocol
|
||||
|
||||
// Package protocol contains data types and code for LSP jsonrpcs
|
||||
// generated automatically from vscode-languageserver-node
|
||||
// commit: 1f688e2f65f3a6fc9ba395380cd7b059667a9ecf
|
||||
// last fetched Tue Jun 09 2020 11:22:02 GMT-0400 (Eastern Daylight Time)
|
||||
// commit: 399de64448129835b53c7efe8962de91681d6cde
|
||||
// last fetched Tue Jul 28 2020 09:32:20 GMT-0400 (Eastern Daylight Time)
|
||||
|
||||
// Code generated (see typescript/README.md) DO NOT EDIT.
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Package protocol contains data types and code for LSP jsonrpcs
|
||||
// generated automatically from vscode-languageserver-node
|
||||
// commit: 1f688e2f65f3a6fc9ba395380cd7b059667a9ecf
|
||||
// last fetched Tue Jun 09 2020 11:22:02 GMT-0400 (Eastern Daylight Time)
|
||||
// commit: 399de64448129835b53c7efe8962de91681d6cde
|
||||
// last fetched Tue Jul 28 2020 09:32:20 GMT-0400 (Eastern Daylight Time)
|
||||
package protocol
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// Code generated (see typescript/README.md) DO NOT EDIT.
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
/**
|
||||
* The parameters passed via a apply workspace edit request.
|
||||
*/
|
||||
@ -588,6 +588,13 @@ type CompletionClientCapabilities struct {
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
InsertReplaceSupport bool `json:"insertReplaceSupport,omitempty"`
|
||||
/**
|
||||
* Client supports to resolve `additionalTextEdits` in the `completionItem/resolve`
|
||||
* request. So servers can postpone computing them.
|
||||
*
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
ResolveAdditionalTextEditsSupport bool `json:"resolveAdditionalTextEditsSupport,omitempty"`
|
||||
} `json:"completionItem,omitempty"`
|
||||
CompletionItemKind struct {
|
||||
/**
|
||||
@ -1594,7 +1601,7 @@ type DocumentSymbolClientCapabilities struct {
|
||||
HierarchicalDocumentSymbolSupport bool `json:"hierarchicalDocumentSymbolSupport,omitempty"`
|
||||
/**
|
||||
* The client supports tags on `SymbolInformation`. Tags are supported on
|
||||
* `DocumentSymbol` if `hierarchicalDocumentSymbolSupport` is set tot true.
|
||||
* `DocumentSymbol` if `hierarchicalDocumentSymbolSupport` is set to true.
|
||||
* Clients supporting tags have to handle unknown tags gracefully.
|
||||
*
|
||||
* @since 3.16.0 - Proposed state
|
||||
@ -2650,13 +2657,38 @@ type SemanticTokens struct {
|
||||
*/
|
||||
ResultID string `json:"resultId,omitempty"`
|
||||
/**
|
||||
* The actual tokens. For a detailed description about how the data is
|
||||
* structured pls see
|
||||
* https://github.com/microsoft/vscode-extension-samples/blob/5ae1f7787122812dcc84e37427ca90af5ee09f14/semantic-tokens-sample/vscode.proposed.d.ts#L71
|
||||
* The actual tokens.
|
||||
*/
|
||||
Data []float64 `json:"data"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
type SemanticTokensDelta struct {
|
||||
ResultID string `json:"resultId,omitempty"`
|
||||
/**
|
||||
* The semantic token edits to transform a previous result into a new result.
|
||||
*/
|
||||
Edits []SemanticTokensEdit `json:"edits"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
type SemanticTokensDeltaParams struct {
|
||||
/**
|
||||
* The text document.
|
||||
*/
|
||||
TextDocument TextDocumentIdentifier `json:"textDocument"`
|
||||
/**
|
||||
* The previous result id.
|
||||
*/
|
||||
PreviousResultID string `json:"previousResultId"`
|
||||
WorkDoneProgressParams
|
||||
PartialResultParams
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
@ -2675,34 +2707,6 @@ type SemanticTokensEdit struct {
|
||||
Data []float64 `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
type SemanticTokensEdits struct {
|
||||
ResultID string `json:"resultId,omitempty"`
|
||||
/**
|
||||
* For a detailed description how these edits are structured pls see
|
||||
* https://github.com/microsoft/vscode-extension-samples/blob/5ae1f7787122812dcc84e37427ca90af5ee09f14/semantic-tokens-sample/vscode.proposed.d.ts#L131
|
||||
*/
|
||||
Edits []SemanticTokensEdit `json:"edits"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
type SemanticTokensEditsParams struct {
|
||||
/**
|
||||
* The text document.
|
||||
*/
|
||||
TextDocument TextDocumentIdentifier `json:"textDocument"`
|
||||
/**
|
||||
* The previous result id.
|
||||
*/
|
||||
PreviousResultID string `json:"previousResultId"`
|
||||
WorkDoneProgressParams
|
||||
PartialResultParams
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0 - Proposed state
|
||||
*/
|
||||
@ -3116,7 +3120,7 @@ type SymbolKind float64
|
||||
|
||||
/**
|
||||
* Symbol tags are extra annotations that tweak the rendering of a symbol.
|
||||
* @since 3.15
|
||||
* @since 3.16
|
||||
*/
|
||||
type SymbolTag float64
|
||||
|
||||
|
@ -2,8 +2,8 @@ package protocol
|
||||
|
||||
// Package protocol contains data types and code for LSP jsonrpcs
|
||||
// generated automatically from vscode-languageserver-node
|
||||
// commit: 1f688e2f65f3a6fc9ba395380cd7b059667a9ecf
|
||||
// last fetched Tue Jun 09 2020 11:22:02 GMT-0400 (Eastern Daylight Time)
|
||||
// commit: 399de64448129835b53c7efe8962de91681d6cde
|
||||
// last fetched Tue Jul 28 2020 09:32:20 GMT-0400 (Eastern Daylight Time)
|
||||
|
||||
// Code generated (see typescript/README.md) DO NOT EDIT.
|
||||
|
||||
@ -27,8 +27,8 @@ type Server interface {
|
||||
DidSave(context.Context, *DidSaveTextDocumentParams) error
|
||||
WillSave(context.Context, *WillSaveTextDocumentParams) error
|
||||
DidChangeWatchedFiles(context.Context, *DidChangeWatchedFilesParams) error
|
||||
SetTraceNotification(context.Context, *SetTraceParams) error
|
||||
LogTraceNotification(context.Context, *LogTraceParams) error
|
||||
SetTrace(context.Context, *SetTraceParams) error
|
||||
LogTrace(context.Context, *LogTraceParams) error
|
||||
Implementation(context.Context, *ImplementationParams) (Definition /*Definition | DefinitionLink[] | null*/, error)
|
||||
TypeDefinition(context.Context, *TypeDefinitionParams) (Definition /*Definition | DefinitionLink[] | null*/, error)
|
||||
DocumentColor(context.Context, *DocumentColorParams) ([]ColorInformation, error)
|
||||
@ -62,8 +62,8 @@ type Server interface {
|
||||
Rename(context.Context, *RenameParams) (*WorkspaceEdit /*WorkspaceEdit | null*/, error)
|
||||
PrepareRename(context.Context, *PrepareRenameParams) (*Range /*Range | { range: Range, placeholder: string } | null*/, error)
|
||||
ExecuteCommand(context.Context, *ExecuteCommandParams) (interface{} /*any | null*/, error)
|
||||
SemanticTokens(context.Context, *SemanticTokensParams) (*SemanticTokens /*SemanticTokens | null*/, error)
|
||||
SemanticTokensEdits(context.Context, *SemanticTokensEditsParams) (interface{} /* SemanticTokens | SemanticTokensEdits | nil*/, error)
|
||||
SemanticTokensFull(context.Context, *SemanticTokensParams) (*SemanticTokens /*SemanticTokens | null*/, error)
|
||||
SemanticTokensFullDelta(context.Context, *SemanticTokensDeltaParams) (interface{} /* SemanticTokens | SemanticTokensDelta | nil*/, error)
|
||||
SemanticTokensRange(context.Context, *SemanticTokensRangeParams) (*SemanticTokens /*SemanticTokens | null*/, error)
|
||||
NonstandardRequest(ctx context.Context, method string, params interface{}) (interface{}, error)
|
||||
}
|
||||
@ -143,19 +143,19 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier,
|
||||
}
|
||||
err := server.DidChangeWatchedFiles(ctx, ¶ms)
|
||||
return true, reply(ctx, nil, err)
|
||||
case "$/setTraceNotification": // notif
|
||||
case "$/setTrace": // notif
|
||||
var params SetTraceParams
|
||||
if err := json.Unmarshal(r.Params(), ¶ms); err != nil {
|
||||
return true, sendParseError(ctx, reply, err)
|
||||
}
|
||||
err := server.SetTraceNotification(ctx, ¶ms)
|
||||
err := server.SetTrace(ctx, ¶ms)
|
||||
return true, reply(ctx, nil, err)
|
||||
case "$/logTraceNotification": // notif
|
||||
case "$/logTrace": // notif
|
||||
var params LogTraceParams
|
||||
if err := json.Unmarshal(r.Params(), ¶ms); err != nil {
|
||||
return true, sendParseError(ctx, reply, err)
|
||||
}
|
||||
err := server.LogTraceNotification(ctx, ¶ms)
|
||||
err := server.LogTrace(ctx, ¶ms)
|
||||
return true, reply(ctx, nil, err)
|
||||
case "textDocument/implementation": // req
|
||||
var params ImplementationParams
|
||||
@ -387,19 +387,19 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier,
|
||||
}
|
||||
resp, err := server.ExecuteCommand(ctx, ¶ms)
|
||||
return true, reply(ctx, resp, err)
|
||||
case "textDocument/semanticTokens": // req
|
||||
case "textDocument/semanticTokens/full": // req
|
||||
var params SemanticTokensParams
|
||||
if err := json.Unmarshal(r.Params(), ¶ms); err != nil {
|
||||
return true, sendParseError(ctx, reply, err)
|
||||
}
|
||||
resp, err := server.SemanticTokens(ctx, ¶ms)
|
||||
resp, err := server.SemanticTokensFull(ctx, ¶ms)
|
||||
return true, reply(ctx, resp, err)
|
||||
case "textDocument/semanticTokens/edits": // req
|
||||
var params SemanticTokensEditsParams
|
||||
case "textDocument/semanticTokens/full/delta": // req
|
||||
var params SemanticTokensDeltaParams
|
||||
if err := json.Unmarshal(r.Params(), ¶ms); err != nil {
|
||||
return true, sendParseError(ctx, reply, err)
|
||||
}
|
||||
resp, err := server.SemanticTokensEdits(ctx, ¶ms)
|
||||
resp, err := server.SemanticTokensFullDelta(ctx, ¶ms)
|
||||
return true, reply(ctx, resp, err)
|
||||
case "textDocument/semanticTokens/range": // req
|
||||
var params SemanticTokensRangeParams
|
||||
@ -458,12 +458,12 @@ func (s *serverDispatcher) DidChangeWatchedFiles(ctx context.Context, params *Di
|
||||
return s.Conn.Notify(ctx, "workspace/didChangeWatchedFiles", params)
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) SetTraceNotification(ctx context.Context, params *SetTraceParams) error {
|
||||
return s.Conn.Notify(ctx, "$/setTraceNotification", params)
|
||||
func (s *serverDispatcher) SetTrace(ctx context.Context, params *SetTraceParams) error {
|
||||
return s.Conn.Notify(ctx, "$/setTrace", params)
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) LogTraceNotification(ctx context.Context, params *LogTraceParams) error {
|
||||
return s.Conn.Notify(ctx, "$/logTraceNotification", params)
|
||||
func (s *serverDispatcher) LogTrace(ctx context.Context, params *LogTraceParams) error {
|
||||
return s.Conn.Notify(ctx, "$/logTrace", params)
|
||||
}
|
||||
func (s *serverDispatcher) Implementation(ctx context.Context, params *ImplementationParams) (Definition /*Definition | DefinitionLink[] | null*/, error) {
|
||||
var result Definition /*Definition | DefinitionLink[] | null*/
|
||||
@ -725,17 +725,17 @@ func (s *serverDispatcher) ExecuteCommand(ctx context.Context, params *ExecuteCo
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) SemanticTokens(ctx context.Context, params *SemanticTokensParams) (*SemanticTokens /*SemanticTokens | null*/, error) {
|
||||
func (s *serverDispatcher) SemanticTokensFull(ctx context.Context, params *SemanticTokensParams) (*SemanticTokens /*SemanticTokens | null*/, error) {
|
||||
var result *SemanticTokens /*SemanticTokens | null*/
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens/full", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) SemanticTokensEdits(ctx context.Context, params *SemanticTokensEditsParams) (interface{} /* SemanticTokens | SemanticTokensEdits | nil*/, error) {
|
||||
var result interface{} /* SemanticTokens | SemanticTokensEdits | nil*/
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens/edits", params, &result); err != nil {
|
||||
func (s *serverDispatcher) SemanticTokensFullDelta(ctx context.Context, params *SemanticTokensDeltaParams) (interface{} /* SemanticTokens | SemanticTokensDelta | nil*/, error) {
|
||||
var result interface{} /* SemanticTokens | SemanticTokensDelta | nil*/
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens/full/delta", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
@ -19,7 +19,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as ts from 'typescript';
|
||||
import * as u from './util';
|
||||
import {constName, getComments, goName, loc, strKind} from './util';
|
||||
import { constName, getComments, goName, loc, strKind } from './util';
|
||||
|
||||
var program: ts.Program;
|
||||
|
||||
@ -27,7 +27,7 @@ function parse() {
|
||||
// this won't complain if some fnames don't exist
|
||||
program = ts.createProgram(
|
||||
u.fnames,
|
||||
{target: ts.ScriptTarget.ES2018, module: ts.ModuleKind.CommonJS});
|
||||
{ target: ts.ScriptTarget.ES2018, module: ts.ModuleKind.CommonJS });
|
||||
program.getTypeChecker(); // finish type checking and assignment
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ function findRPCs(node: ts.Node) {
|
||||
if (rpc == '') throw new Error(`no name found at ${loc(x)}`);
|
||||
// remember the implied types
|
||||
const [a, b] = ptypes.get(rpc);
|
||||
const add = function(n: ts.Node) {
|
||||
const add = function (n: ts.Node) {
|
||||
rpcTypes.add(goName(n.getText()))
|
||||
};
|
||||
underlying(a, add);
|
||||
@ -130,8 +130,8 @@ function setReceives() {
|
||||
// it would be nice to have some independent check on this
|
||||
// (this logic fails if the server ever sends $/canceRequest
|
||||
// or $/progress)
|
||||
req.forEach((_, k) => {receives.set(k, 'server')});
|
||||
not.forEach((_, k) => {receives.set(k, 'server')});
|
||||
req.forEach((_, k) => { receives.set(k, 'server') });
|
||||
not.forEach((_, k) => { receives.set(k, 'server') });
|
||||
receives.set('window/showMessage', 'client');
|
||||
receives.set('window/showMessageRequest', 'client');
|
||||
receives.set('window/logMessage', 'client');
|
||||
@ -178,7 +178,7 @@ function newData(n: ts.Node, nm: string): Data {
|
||||
|
||||
// for debugging, produce a skeleton description
|
||||
function strData(d: Data): string {
|
||||
const f = function(na: ts.NodeArray<any>): number {
|
||||
const f = function (na: ts.NodeArray<any>): number {
|
||||
return na.length
|
||||
};
|
||||
return `D(${d.name}) g;${f(d.generics)} a:${f(d.as)} p:${f(d.properties)} s:${
|
||||
@ -204,7 +204,7 @@ function genTypes(node: ts.Node) {
|
||||
const v: ts.InterfaceDeclaration = node;
|
||||
// need to check the members, many of which are disruptive
|
||||
let mems: ts.TypeElement[] = [];
|
||||
const f = function(t: ts.TypeElement) {
|
||||
const f = function (t: ts.TypeElement) {
|
||||
if (ts.isPropertySignature(t)) {
|
||||
mems.push(t);
|
||||
} else if (ts.isMethodSignature(t) || ts.isCallSignatureDeclaration(t)) {
|
||||
@ -262,7 +262,7 @@ function genTypes(node: ts.Node) {
|
||||
const b: ts.ModuleBlock = v.body;
|
||||
var s: ts.Statement[] = [];
|
||||
// we don't want most of these
|
||||
const fx = function(x: ts.Statement) {
|
||||
const fx = function (x: ts.Statement) {
|
||||
if (ts.isFunctionDeclaration(x)) {
|
||||
return
|
||||
};
|
||||
@ -297,7 +297,7 @@ function genTypes(node: ts.Node) {
|
||||
const v: ts.ClassDeclaration = node;
|
||||
var d: ts.PropertyDeclaration[] = [];
|
||||
// look harder at the PropertyDeclarations.
|
||||
const wanted = function(c: ts.ClassElement): string {
|
||||
const wanted = function (c: ts.ClassElement): string {
|
||||
if (ts.isConstructorDeclaration(c)) {
|
||||
return ''
|
||||
};
|
||||
@ -361,6 +361,7 @@ function dataMerge(a: Data, b: Data): Data {
|
||||
// want the Interface
|
||||
return a.properties.length > 0 ? a : b;
|
||||
case 'TextDocumentContentChangeEvent': // almost the same
|
||||
case 'TokenFormat':
|
||||
return a;
|
||||
}
|
||||
console.log(
|
||||
@ -387,7 +388,7 @@ function checkOnce() {
|
||||
// helper function to find underlying types
|
||||
function underlying(n: ts.Node, f: (n: ts.Node) => void) {
|
||||
if (!n) return;
|
||||
const ff = function(n: ts.Node) {
|
||||
const ff = function (n: ts.Node) {
|
||||
underlying(n, f)
|
||||
};
|
||||
if (ts.isIdentifier(n)) {
|
||||
@ -436,7 +437,7 @@ function underlying(n: ts.Node, f: (n: ts.Node) => void) {
|
||||
// Simplest way to the transitive closure is to stabilize the size of seenTypes
|
||||
// but it is slow
|
||||
function moreTypes() {
|
||||
const extra = function(s: string) {
|
||||
const extra = function (s: string) {
|
||||
if (!data.has(s)) throw new Error(`moreTypes needs ${s}`);
|
||||
seenTypes.set(s, data.get(s))
|
||||
};
|
||||
@ -456,17 +457,17 @@ function moreTypes() {
|
||||
old = seenTypes.size
|
||||
|
||||
const m = new Map<string, Data>();
|
||||
const add = function(n: ts.Node) {
|
||||
const add = function (n: ts.Node) {
|
||||
const nm = goName(n.getText());
|
||||
if (seenTypes.has(nm) || m.has(nm)) return;
|
||||
// For generic parameters, this might set it to undefined
|
||||
m.set(nm, data.get(nm));
|
||||
};
|
||||
// expect all the heritage clauses have single Identifiers
|
||||
const h = function(n: ts.Node) {
|
||||
const h = function (n: ts.Node) {
|
||||
underlying(n, add);
|
||||
};
|
||||
const f = function(x: ts.NodeArray<ts.Node>) {
|
||||
const f = function (x: ts.NodeArray<ts.Node>) {
|
||||
x.forEach(h)
|
||||
};
|
||||
seenTypes.forEach((d: Data) => d && f(d.as))
|
||||
@ -513,7 +514,7 @@ function goInterface(d: Data, nm: string) {
|
||||
let ans = `type ${goName(nm)} struct {\n`;
|
||||
|
||||
// generate the code for each member
|
||||
const g = function(n: ts.TypeElement) {
|
||||
const g = function (n: ts.TypeElement) {
|
||||
if (!ts.isPropertySignature(n))
|
||||
throw new Error(`expected PropertySignature got ${strKind(n)} `);
|
||||
ans = ans.concat(getComments(n));
|
||||
@ -532,7 +533,7 @@ function goInterface(d: Data, nm: string) {
|
||||
d.properties.forEach(g)
|
||||
// heritage clauses become embedded types
|
||||
// check they are all Identifiers
|
||||
const f = function(n: ts.ExpressionWithTypeArguments) {
|
||||
const f = function (n: ts.ExpressionWithTypeArguments) {
|
||||
if (!ts.isIdentifier(n.expression))
|
||||
throw new Error(`Interface ${nm} heritage ${strKind(n.expression)} `);
|
||||
ans = ans.concat(goName(n.expression.getText()), '\n')
|
||||
@ -555,7 +556,7 @@ function goModule(d: Data, nm: string) {
|
||||
// They are VariableStatements with x.declarationList having a single
|
||||
// VariableDeclaration
|
||||
let isNumeric = false;
|
||||
const f = function(n: ts.Statement, i: number) {
|
||||
const f = function (n: ts.Statement, i: number) {
|
||||
if (!ts.isVariableStatement(n)) {
|
||||
throw new Error(` ${nm} ${i} expected VariableStatement,
|
||||
got ${strKind(n)}`);
|
||||
@ -582,7 +583,7 @@ function goModule(d: Data, nm: string) {
|
||||
// generate Go code for an enum. Both types and named constants
|
||||
function goEnum(d: Data, nm: string) {
|
||||
let isNumeric = false
|
||||
const f = function(v: ts.EnumMember, j: number) { // same as goModule
|
||||
const f = function (v: ts.EnumMember, j: number) { // same as goModule
|
||||
if (!v.initializer)
|
||||
throw new Error(`goEnum no initializer ${nm} ${j} ${v.name.getText()}`);
|
||||
isNumeric = strKind(v.initializer) == 'NumericLiteral';
|
||||
@ -635,6 +636,10 @@ function goType(n: ts.TypeNode, nm: string): string {
|
||||
} else if (strKind(n) == 'ObjectKeyword') {
|
||||
return 'interface{}'
|
||||
} else if (ts.isArrayTypeNode(n)) {
|
||||
if (nm === 'arguments') {
|
||||
// Command and ExecuteCommandParams
|
||||
return '[]json.RawMessage';
|
||||
}
|
||||
return `[]${goType(n.elementType, nm)}`
|
||||
} else if (ts.isParenthesizedTypeNode(n)) {
|
||||
return goType(n.type, nm)
|
||||
@ -757,7 +762,7 @@ function goIntersectionType(n: ts.IntersectionTypeNode, nm: string): string {
|
||||
if (nm == 'ServerCapabilities') return expandIntersection(n);
|
||||
let inner = '';
|
||||
n.types.forEach(
|
||||
(t: ts.TypeNode) => {inner = inner.concat(goType(t, nm), '\n')});
|
||||
(t: ts.TypeNode) => { inner = inner.concat(goType(t, nm), '\n') });
|
||||
return `struct{ \n${inner}} `
|
||||
}
|
||||
|
||||
@ -766,7 +771,7 @@ function goIntersectionType(n: ts.IntersectionTypeNode, nm: string): string {
|
||||
// of them by name. The names that occur once can be output. The names
|
||||
// that occur more than once need to be combined.
|
||||
function expandIntersection(n: ts.IntersectionTypeNode): string {
|
||||
const bad = function(n: ts.Node, s: string) {
|
||||
const bad = function (n: ts.Node, s: string) {
|
||||
return new Error(`expandIntersection ${strKind(n)} ${s}`)
|
||||
};
|
||||
let props = new Map<string, ts.PropertySignature[]>();
|
||||
@ -818,7 +823,7 @@ function expandIntersection(n: ts.IntersectionTypeNode): string {
|
||||
function goTypeLiteral(n: ts.TypeLiteralNode, nm: string): string {
|
||||
let ans: string[] = []; // in case we generate a new extra type
|
||||
let res = 'struct{\n' // the actual answer usually
|
||||
const g = function(nx: ts.TypeElement) {
|
||||
const g = function (nx: ts.TypeElement) {
|
||||
// add the json, as in goInterface(). Strange inside union types.
|
||||
if (ts.isPropertySignature(nx)) {
|
||||
let json = u.JSON(nx);
|
||||
@ -858,6 +863,7 @@ function outputTypes() {
|
||||
v.sort();
|
||||
v.forEach((x) => toGo(seenTypes.get(x), x))
|
||||
u.prgo(u.computeHeader(true))
|
||||
u.prgo(`import "encoding/json"\n\n`);
|
||||
typesOut.forEach((s) => {
|
||||
u.prgo(s);
|
||||
// it's more convenient not to have to think about trailing newlines
|
||||
@ -1003,8 +1009,7 @@ function methodName(m: string): string {
|
||||
let i = m.indexOf('/');
|
||||
let s = m.substring(i + 1);
|
||||
let x = s[0].toUpperCase() + s.substring(1);
|
||||
const j = x.indexOf('/')
|
||||
if (j >= 0) {
|
||||
for (let j = x.indexOf('/'); j >= 0; j = x.indexOf('/')) {
|
||||
let suffix = x.substring(j + 1)
|
||||
suffix = suffix[0].toUpperCase() + suffix.substring(1)
|
||||
let prefix = x.substring(0, j)
|
||||
@ -1064,7 +1069,7 @@ function output(side: side) {
|
||||
side.outputFile = `ts${side.name}.go`;
|
||||
side.fd = fs.openSync(side.outputFile, 'w');
|
||||
}
|
||||
const f = function(s: string) {
|
||||
const f = function (s: string) {
|
||||
fs.writeSync(side.fd, s);
|
||||
fs.writeSync(side.fd, '\n');
|
||||
};
|
||||
@ -1080,17 +1085,17 @@ function output(side: side) {
|
||||
`);
|
||||
const a = side.name[0].toUpperCase() + side.name.substring(1)
|
||||
f(`type ${a} interface {`);
|
||||
side.methods.forEach((v) => {f(v)});
|
||||
side.methods.forEach((v) => { f(v) });
|
||||
f('}\n');
|
||||
f(`func ${side.name}Dispatch(ctx context.Context, ${side.name} ${a}, reply jsonrpc2.Replier, r jsonrpc2.Request) (bool, error) {
|
||||
switch r.Method() {`);
|
||||
side.cases.forEach((v) => {f(v)});
|
||||
side.cases.forEach((v) => { f(v) });
|
||||
f(`
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}`);
|
||||
side.calls.forEach((v) => {f(v)});
|
||||
side.calls.forEach((v) => { f(v) });
|
||||
}
|
||||
|
||||
// Handling of non-standard requests, so we can add gopls-specific calls.
|
||||
|
@ -14,7 +14,7 @@ export const fnames = [
|
||||
`${dir}/${srcDir}/protocol/src/browser/main.ts`, `${dir}${srcDir}/types/src/main.ts`,
|
||||
`${dir}${srcDir}/jsonrpc/src/node/main.ts`
|
||||
];
|
||||
export const gitHash = '1f688e2f65f3a6fc9ba395380cd7b059667a9ecf'
|
||||
export const gitHash = '399de64448129835b53c7efe8962de91681d6cde'
|
||||
let outFname = 'tsprotocol.go';
|
||||
let fda: number, fdb: number, fde: number; // file descriptors
|
||||
|
||||
@ -86,7 +86,7 @@ export function goName(s: string): string {
|
||||
if (s.charAt(0) == '_') {
|
||||
ans = 'Inner' + s.substring(1)
|
||||
}
|
||||
else {ans = s.substring(0, 1).toUpperCase() + s.substring(1)};
|
||||
else { ans = s.substring(0, 1).toUpperCase() + s.substring(1) };
|
||||
ans = ans.replace(/Uri$/, 'URI')
|
||||
ans = ans.replace(/Id$/, 'ID')
|
||||
return ans
|
||||
@ -131,7 +131,7 @@ export function getComments(node: ts.Node): string {
|
||||
|
||||
export function printAST(program: ts.Program) {
|
||||
// dump the ast, for debugging
|
||||
const f = function(n: ts.Node) {
|
||||
const f = function (n: ts.Node) {
|
||||
describe(n, pra)
|
||||
};
|
||||
for (const sourceFile of program.getSourceFiles()) {
|
||||
@ -173,7 +173,7 @@ function describe(node: ts.Node, pr: (s: string) => any) {
|
||||
else if (ts.isStringLiteral(n)) {
|
||||
pr(`${indent} ${loc(n)} ${strKind(n)} ${n.text} \n`)
|
||||
}
|
||||
else {pr(`${indent} ${loc(n)} ${strKind(n)} \n`)};
|
||||
else { pr(`${indent} ${loc(n)} ${strKind(n)} \n`) };
|
||||
indent += ' .'
|
||||
ts.forEachChild(n, f)
|
||||
indent = indent.slice(0, indent.length - 2)
|
||||
@ -201,7 +201,7 @@ export function loc(node: ts.Node): string {
|
||||
// as part of printing the AST tree
|
||||
function kinds(n: ts.Node): string {
|
||||
let res = 'Seen ' + strKind(n);
|
||||
function f(n: ts.Node): void {res += ' ' + strKind(n)};
|
||||
function f(n: ts.Node): void { res += ' ' + strKind(n) };
|
||||
ts.forEachChild(n, f)
|
||||
return res
|
||||
}
|
||||
|
@ -112,8 +112,8 @@ func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedPa
|
||||
return s.initialized(ctx, params)
|
||||
}
|
||||
|
||||
func (s *Server) LogTraceNotification(context.Context, *protocol.LogTraceParams) error {
|
||||
return notImplemented("LogTraceNotification")
|
||||
func (s *Server) LogTrace(context.Context, *protocol.LogTraceParams) error {
|
||||
return notImplemented("LogTrace")
|
||||
}
|
||||
|
||||
func (s *Server) NonstandardRequest(ctx context.Context, method string, params interface{}) (interface{}, error) {
|
||||
@ -164,20 +164,20 @@ func (s *Server) SelectionRange(context.Context, *protocol.SelectionRangeParams)
|
||||
return nil, notImplemented("SelectionRange")
|
||||
}
|
||||
|
||||
func (s *Server) SemanticTokens(context.Context, *protocol.SemanticTokensParams) (*protocol.SemanticTokens, error) {
|
||||
return nil, notImplemented("SemanticTokens")
|
||||
func (s *Server) SemanticTokensFull(context.Context, *protocol.SemanticTokensParams) (*protocol.SemanticTokens, error) {
|
||||
return nil, notImplemented("SemanticTokensFull")
|
||||
}
|
||||
|
||||
func (s *Server) SemanticTokensEdits(context.Context, *protocol.SemanticTokensEditsParams) (interface{}, error) {
|
||||
return nil, notImplemented("SemanticTokensEdits")
|
||||
func (s *Server) SemanticTokensFullDelta(context.Context, *protocol.SemanticTokensDeltaParams) (interface{}, error) {
|
||||
return nil, notImplemented("SemanticTokensFullDelta")
|
||||
}
|
||||
|
||||
func (s *Server) SemanticTokensRange(context.Context, *protocol.SemanticTokensRangeParams) (*protocol.SemanticTokens, error) {
|
||||
return nil, notImplemented("SemanticTokensRange")
|
||||
}
|
||||
|
||||
func (s *Server) SetTraceNotification(context.Context, *protocol.SetTraceParams) error {
|
||||
return notImplemented("SetTraceNotification")
|
||||
func (s *Server) SetTrace(context.Context, *protocol.SetTraceParams) error {
|
||||
return notImplemented("SetTrace")
|
||||
}
|
||||
|
||||
func (s *Server) Shutdown(ctx context.Context) error {
|
||||
|
Loading…
Reference in New Issue
Block a user