File: main.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.5.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports
  • size: 16,592 kB
  • sloc: javascript: 2,011; asm: 1,635; sh: 192; yacc: 155; makefile: 52; ansic: 8
file content (93 lines) | stat: -rw-r--r-- 2,321 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.19
// +build go1.19

package main

import (
	"flag"
	"fmt"
	"log"
	"os"
)

var (
	// git clone https://github.com/microsoft/vscode-languageserver-node.git
	repodir   = flag.String("d", "", "directory of vscode-languageserver-node")
	outputdir = flag.String("o", "gen", "output directory")
	cmpolder  = flag.String("c", "", "directory of older generated code")
)

func main() {
	log.SetFlags(log.Lshortfile) // log file name and line number, not time
	flag.Parse()

	if *repodir == "" {
		*repodir = fmt.Sprintf("%s/vscode-languageserver-node", os.Getenv("HOME"))
	}
	spec := parse(*repodir)

	// index the information in the specification
	spec.indexRPCInfo() // messages
	spec.indexDefInfo() // named types

}

func (s *spec) indexRPCInfo() {
	for _, r := range s.model.Requests {
		r := r
		s.byMethod[r.Method] = &r
	}
	for _, n := range s.model.Notifications {
		n := n
		if n.Method == "$/cancelRequest" {
			// viewed as too confusing to generate
			continue
		}
		s.byMethod[n.Method] = &n
	}
}

func (sp *spec) indexDefInfo() {
	for _, s := range sp.model.Structures {
		s := s
		sp.byName[s.Name] = &s
	}
	for _, e := range sp.model.Enumerations {
		e := e
		sp.byName[e.Name] = &e
	}
	for _, ta := range sp.model.TypeAliases {
		ta := ta
		sp.byName[ta.Name] = &ta
	}

	// some Structure and TypeAlias names need to be changed for Go
	// so byName contains the name used in the .json file, and
	// the Name field contains the Go version of the name.
	v := sp.model.Structures
	for i, s := range v {
		switch s.Name {
		case "_InitializeParams": // _ is not upper case
			v[i].Name = "XInitializeParams"
		case "ConfigurationParams": // gopls compatibility
			v[i].Name = "ParamConfiguration"
		case "InitializeParams": // gopls compatibility
			v[i].Name = "ParamInitialize"
		case "PreviousResultId": // Go naming convention
			v[i].Name = "PreviousResultID"
		case "WorkspaceFoldersServerCapabilities": // gopls compatibility
			v[i].Name = "WorkspaceFolders5Gn"
		}
	}
	w := sp.model.TypeAliases
	for i, t := range w {
		switch t.Name {
		case "PrepareRenameResult": // gopls compatibility
			w[i].Name = "PrepareRename2Gn"
		}
	}
}