55 "context"
66 "fmt"
77 "os"
8- "path"
98 "path/filepath"
9+ "strings"
1010 "testing"
1111
1212 "github.com/docker/docker-language-server/internal/tliron/glsp/protocol"
@@ -31,84 +31,58 @@ func TestDocumentLink(t *testing.T) {
3131
3232 homedir , err := os .UserHomeDir ()
3333 require .NoError (t , err )
34-
35- testFolder := path .Join (homedir , t .Name ())
36- parentFolder , err := filepath .Abs (path .Join (testFolder , ".." ))
37- require .NoError (t , err )
34+ testFolder := filepath .Join (homedir , t .Name ())
3835
3936 testCases := []struct {
40- name string
41- content string
42- links []protocol.DocumentLink
37+ name string
38+ content string
39+ linkRange protocol.Range
40+ path string
41+ links []protocol.DocumentLink
4342 }{
4443 {
4544 name : "dockerfile attribute in targets block" ,
4645 content : "target \" api\" {\n dockerfile = \" Dockerfile.api\" \n }" ,
47- links : []protocol.DocumentLink {
48- {
49- Range : protocol.Range {
50- Start : protocol.Position {Line : 1 , Character : 16 },
51- End : protocol.Position {Line : 1 , Character : 30 },
52- },
53- Target : types .CreateStringPointer (fmt .Sprintf ("file://%v" , path .Join (homedir , "TestDocumentLink" , "Dockerfile.api" ))),
54- Tooltip : types .CreateStringPointer (path .Join (homedir , "TestDocumentLink" , "Dockerfile.api" )),
55- },
46+ path : filepath .Join (homedir , "TestDocumentLink" , "Dockerfile.api" ),
47+ linkRange : protocol.Range {
48+ Start : protocol.Position {Line : 1 , Character : 16 },
49+ End : protocol.Position {Line : 1 , Character : 30 },
5650 },
5751 },
5852 {
5953 name : "./dockerfile attribute in targets block" ,
6054 content : "target \" api\" {\n dockerfile = \" ./Dockerfile.api\" \n }" ,
61- links : []protocol.DocumentLink {
62- {
63- Range : protocol.Range {
64- Start : protocol.Position {Line : 1 , Character : 16 },
65- End : protocol.Position {Line : 1 , Character : 32 },
66- },
67- Target : types .CreateStringPointer (fmt .Sprintf ("file://%v" , path .Join (homedir , "TestDocumentLink" , "Dockerfile.api" ))),
68- Tooltip : types .CreateStringPointer (path .Join (homedir , "TestDocumentLink" , "Dockerfile.api" )),
69- },
55+ path : filepath .Join (homedir , "TestDocumentLink" , "Dockerfile.api" ),
56+ linkRange : protocol.Range {
57+ Start : protocol.Position {Line : 1 , Character : 16 },
58+ End : protocol.Position {Line : 1 , Character : 32 },
7059 },
7160 },
7261 {
7362 name : "../dockerfile attribute in targets block" ,
7463 content : "target \" api\" {\n dockerfile = \" ../Dockerfile.api\" \n }" ,
75- links : []protocol.DocumentLink {
76- {
77- Range : protocol.Range {
78- Start : protocol.Position {Line : 1 , Character : 16 },
79- End : protocol.Position {Line : 1 , Character : 33 },
80- },
81- Target : types .CreateStringPointer (fmt .Sprintf ("file://%v" , path .Join (parentFolder , "Dockerfile.api" ))),
82- Tooltip : types .CreateStringPointer (path .Join (parentFolder , "Dockerfile.api" )),
83- },
64+ path : filepath .Join (homedir , "Dockerfile.api" ),
65+ linkRange : protocol.Range {
66+ Start : protocol.Position {Line : 1 , Character : 16 },
67+ End : protocol.Position {Line : 1 , Character : 33 },
8468 },
8569 },
8670 {
8771 name : "folder/dockerfile attribute in targets block" ,
8872 content : "target \" api\" {\n dockerfile = \" folder/Dockerfile.api\" \n }" ,
89- links : []protocol.DocumentLink {
90- {
91- Range : protocol.Range {
92- Start : protocol.Position {Line : 1 , Character : 16 },
93- End : protocol.Position {Line : 1 , Character : 37 },
94- },
95- Target : types .CreateStringPointer (fmt .Sprintf ("file://%v" , path .Join (homedir , "TestDocumentLink" , "folder" , "Dockerfile.api" ))),
96- Tooltip : types .CreateStringPointer (path .Join (homedir , "TestDocumentLink" , "folder" , "Dockerfile.api" )),
97- },
73+ path : filepath .Join (homedir , "TestDocumentLink" , "folder" , "Dockerfile.api" ),
74+ linkRange : protocol.Range {
75+ Start : protocol.Position {Line : 1 , Character : 16 },
76+ End : protocol.Position {Line : 1 , Character : 37 },
9877 },
9978 },
10079 {
10180 name : "../folder/dockerfile attribute in targets block" ,
10281 content : "target \" api\" {\n dockerfile = \" ../folder/Dockerfile.api\" \n }" ,
103- links : []protocol.DocumentLink {
104- {
105- Range : protocol.Range {
106- Start : protocol.Position {Line : 1 , Character : 16 },
107- End : protocol.Position {Line : 1 , Character : 40 },
108- },
109- Target : types .CreateStringPointer (fmt .Sprintf ("file://%v" , path .Join (parentFolder , "folder/Dockerfile.api" ))),
110- Tooltip : types .CreateStringPointer (path .Join (parentFolder , "folder/Dockerfile.api" )),
111- },
82+ path : filepath .Join (homedir , "folder/Dockerfile.api" ),
83+ linkRange : protocol.Range {
84+ Start : protocol.Position {Line : 1 , Character : 16 },
85+ End : protocol.Position {Line : 1 , Character : 40 },
11286 },
11387 },
11488 }
@@ -128,7 +102,14 @@ func TestDocumentLink(t *testing.T) {
128102 TextDocument : protocol.TextDocumentIdentifier {URI : didOpen .TextDocument .URI },
129103 }, & result )
130104 require .NoError (t , err )
131- require .Equal (t , tc .links , result )
105+ links := []protocol.DocumentLink {
106+ {
107+ Range : tc .linkRange ,
108+ Target : types .CreateStringPointer (fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (tc .path ), "/" ))),
109+ Tooltip : types .CreateStringPointer (tc .path ),
110+ },
111+ }
112+ require .Equal (t , links , result )
132113 })
133114 }
134115}
0 commit comments