Skip to content

Commit 4819268

Browse files
committed
Stylistic changes
1 parent d64b6e6 commit 4819268

File tree

5 files changed

+164
-156
lines changed

5 files changed

+164
-156
lines changed

internal/codeintel/gitutil.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func InferMergeBase() (string, error) {
4848
return runGitCommand("merge-base", "HEAD", "origin/HEAD")
4949
}
5050

51+
// GitRoot returns the absolute path to the root of the git repository.
52+
func GitRoot() (string, error) {
53+
return runGitCommand("rev-parse", "--show-toplevel")
54+
}
55+
5156
// InferRoot gets the path relative to the root of the git clone enclosing the given file path.
5257
func InferRoot(file string) (string, error) {
5358
topLevel, err := runGitCommand("rev-parse", "--show-toplevel")

internal/lsp/query.go

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,39 @@ package lsp
22

33
import "context"
44

5+
type Position struct {
6+
Line int `json:"line"`
7+
Character int `json:"character"`
8+
}
9+
10+
type RangeResult struct {
11+
Start Position `json:"start"`
12+
End Position `json:"end"`
13+
}
14+
15+
type LocationNode struct {
16+
Resource struct {
17+
Path string `json:"path"`
18+
Repository struct {
19+
Name string `json:"name"`
20+
} `json:"repository"`
21+
Commit struct {
22+
OID string `json:"oid"`
23+
} `json:"commit"`
24+
} `json:"resource"`
25+
Range RangeResult `json:"range"`
26+
}
27+
28+
// Hover
29+
530
const hoverQuery = `
6-
query Hover($repository: String!, $commit: String!, $path: String!, $line: Int!, $character: Int!) {
31+
query Hover(
32+
$repository: String!
33+
$commit: String!
34+
$path: String!
35+
$line: Int!
36+
$character: Int!
37+
) {
738
repository(name: $repository) {
839
commit(rev: $commit) {
940
blob(path: $path) {
@@ -37,16 +68,6 @@ type HoverResult struct {
3768
Range *RangeResult `json:"range"`
3869
}
3970

40-
type RangeResult struct {
41-
Start Position `json:"start"`
42-
End Position `json:"end"`
43-
}
44-
45-
type Position struct {
46-
Line int `json:"line"`
47-
Character int `json:"character"`
48-
}
49-
5071
type hoverResponse struct {
5172
Repository *struct {
5273
Commit *struct {
@@ -59,7 +80,9 @@ type hoverResponse struct {
5980
} `json:"repository"`
6081
}
6182

62-
func (s *Server) queryHover(ctx context.Context, path string, line, character int) (*HoverResult, error) {
83+
func (s *Server) queryHover(
84+
ctx context.Context, path string, line, character int,
85+
) (*HoverResult, error) {
6386
vars := map[string]any{
6487
"repository": s.repoName,
6588
"commit": s.commit,
@@ -88,8 +111,16 @@ func (s *Server) queryHover(ctx context.Context, path string, line, character in
88111
return result.Repository.Commit.Blob.LSIF.Hover, nil
89112
}
90113

114+
// Definitions
115+
91116
const definitionsQuery = `
92-
query Definitions($repository: String!, $commit: String!, $path: String!, $line: Int!, $character: Int!) {
117+
query Definitions(
118+
$repository: String!
119+
$commit: String!
120+
$path: String!
121+
$line: Int!
122+
$character: Int!
123+
) {
93124
repository(name: $repository) {
94125
commit(rev: $commit) {
95126
blob(path: $path) {
@@ -124,19 +155,6 @@ query Definitions($repository: String!, $commit: String!, $path: String!, $line:
124155
}
125156
`
126157

127-
type LocationNode struct {
128-
Resource struct {
129-
Path string `json:"path"`
130-
Repository struct {
131-
Name string `json:"name"`
132-
} `json:"repository"`
133-
Commit struct {
134-
OID string `json:"oid"`
135-
} `json:"commit"`
136-
} `json:"resource"`
137-
Range RangeResult `json:"range"`
138-
}
139-
140158
type definitionsResponse struct {
141159
Repository *struct {
142160
Commit *struct {
@@ -151,7 +169,9 @@ type definitionsResponse struct {
151169
} `json:"repository"`
152170
}
153171

154-
func (s *Server) queryDefinitions(ctx context.Context, path string, line, character int) ([]LocationNode, error) {
172+
func (s *Server) queryDefinitions(
173+
ctx context.Context, path string, line, character int,
174+
) ([]LocationNode, error) {
155175
vars := map[string]any{
156176
"repository": s.repoName,
157177
"commit": s.commit,
@@ -180,8 +200,16 @@ func (s *Server) queryDefinitions(ctx context.Context, path string, line, charac
180200
return result.Repository.Commit.Blob.LSIF.Definitions.Nodes, nil
181201
}
182202

203+
// References
204+
183205
const referencesQuery = `
184-
query References($repository: String!, $commit: String!, $path: String!, $line: Int!, $character: Int!) {
206+
query References(
207+
$repository: String!
208+
$commit: String!
209+
$path: String!
210+
$line: Int!
211+
$character: Int!
212+
) {
185213
repository(name: $repository) {
186214
commit(rev: $commit) {
187215
blob(path: $path) {
@@ -230,7 +258,9 @@ type referencesResponse struct {
230258
} `json:"repository"`
231259
}
232260

233-
func (s *Server) queryReferences(ctx context.Context, path string, line, character int) ([]LocationNode, error) {
261+
func (s *Server) queryReferences(
262+
ctx context.Context, path string, line, character int,
263+
) ([]LocationNode, error) {
234264
vars := map[string]any{
235265
"repository": s.repoName,
236266
"commit": s.commit,

internal/lsp/query_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func TestQueryHover(t *testing.T) {
9898
t.Run(tt.name, func(t *testing.T) {
9999
mockClient := &mock.Client{}
100100
mockRequest := &mock.Request{Response: tt.response}
101-
mockRequest.On("Do", context.Background(), &hoverResponse{}).Return(true, nil)
101+
mockRequest.On("Do", context.Background(), &hoverResponse{}).
102+
Return(true, nil)
102103
mockClient.On("NewRequest", hoverQuery, map[string]any{
103104
"repository": "github.com/test/repo",
104105
"commit": "abc123",
@@ -231,7 +232,8 @@ func TestQueryDefinitions(t *testing.T) {
231232
t.Run(tt.name, func(t *testing.T) {
232233
mockClient := &mock.Client{}
233234
mockRequest := &mock.Request{Response: tt.response}
234-
mockRequest.On("Do", context.Background(), &definitionsResponse{}).Return(true, nil)
235+
mockRequest.On("Do", context.Background(), &definitionsResponse{}).
236+
Return(true, nil)
235237
mockClient.On("NewRequest", definitionsQuery, map[string]any{
236238
"repository": "github.com/test/repo",
237239
"commit": "abc123",
@@ -329,7 +331,8 @@ func TestQueryReferences(t *testing.T) {
329331
t.Run(tt.name, func(t *testing.T) {
330332
mockClient := &mock.Client{}
331333
mockRequest := &mock.Request{Response: tt.response}
332-
mockRequest.On("Do", context.Background(), &referencesResponse{}).Return(true, nil)
334+
mockRequest.On("Do", context.Background(), &referencesResponse{}).
335+
Return(true, nil)
333336
mockClient.On("NewRequest", referencesQuery, map[string]any{
334337
"repository": "github.com/test/repo",
335338
"commit": "abc123",

0 commit comments

Comments
 (0)