@@ -2835,7 +2835,12 @@ services:
2835
2835
},
2836
2836
}
2837
2837
2838
- composeFileURI := fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (filepath .Join (os .TempDir (), "compose.yaml" )), "/" ))
2838
+ dir , err := os .MkdirTemp (os .TempDir (), fmt .Sprintf ("%v-%v" , t .Name (), time .Now ().UnixMilli ()))
2839
+ require .NoError (t , err )
2840
+ t .Cleanup (func () {
2841
+ require .NoError (t , os .RemoveAll (dir ))
2842
+ })
2843
+ composeFileURI := fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (filepath .Join (dir , "compose.yaml" )), "/" ))
2839
2844
2840
2845
for _ , tc := range testCases {
2841
2846
t .Run (tc .name , func (t * testing.T ) {
@@ -4967,31 +4972,6 @@ services:
4967
4972
}
4968
4973
4969
4974
func TestCompletion_FileStructure (t * testing.T ) {
4970
- dir , err := os .MkdirTemp (os .TempDir (), fmt .Sprintf ("%v-%v" , t .Name (), time .Now ().UnixMilli ()))
4971
- require .NoError (t , err )
4972
- t .Cleanup (func () {
4973
- require .NoError (t , os .RemoveAll (dir ))
4974
- })
4975
-
4976
- fileStructure := []struct {
4977
- name string
4978
- isDir bool
4979
- }{
4980
- {name : "a.txt" , isDir : false },
4981
- {name : "b" , isDir : true },
4982
- {name : "folder" , isDir : true },
4983
- {name : "folder/subfile.txt" , isDir : false },
4984
- }
4985
- for _ , entry := range fileStructure {
4986
- if entry .isDir {
4987
- require .NoError (t , os .Mkdir (filepath .Join (dir , entry .name ), 0755 ))
4988
- } else {
4989
- f , err := os .Create (filepath .Join (dir , entry .name ))
4990
- require .NoError (t , err )
4991
- require .NoError (t , f .Close ())
4992
- }
4993
- }
4994
-
4995
4975
testCases := []struct {
4996
4976
name string
4997
4977
content string
@@ -5116,6 +5096,44 @@ secrets:
5116
5096
line : 3 ,
5117
5097
character : 10 ,
5118
5098
},
5099
+ {
5100
+ name : "include - env_file attribute" ,
5101
+ content : `
5102
+ include:
5103
+ - env_file: ` ,
5104
+ hideFiles : false ,
5105
+ line : 2 ,
5106
+ character : 14 ,
5107
+ },
5108
+ {
5109
+ name : "include - env_file attribute's string array items" ,
5110
+ content : `
5111
+ include:
5112
+ - env_file:
5113
+ - ` ,
5114
+ hideFiles : false ,
5115
+ line : 3 ,
5116
+ character : 6 ,
5117
+ },
5118
+ {
5119
+ name : "include - path attribute" ,
5120
+ content : `
5121
+ include:
5122
+ - path: ` ,
5123
+ hideFiles : false ,
5124
+ line : 2 ,
5125
+ character : 10 ,
5126
+ },
5127
+ {
5128
+ name : "include - path attribute's string array items" ,
5129
+ content : `
5130
+ include:
5131
+ - path:
5132
+ - ` ,
5133
+ hideFiles : false ,
5134
+ line : 3 ,
5135
+ character : 6 ,
5136
+ },
5119
5137
}
5120
5138
5121
5139
setups := []struct {
@@ -5207,6 +5225,7 @@ secrets:
5207
5225
},
5208
5226
}
5209
5227
5228
+ dir := createFileStructure (t )
5210
5229
composeFileURI := fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (filepath .Join (dir , "compose.yaml" )), "/" ))
5211
5230
5212
5231
for _ , tc := range testCases {
@@ -5231,6 +5250,83 @@ secrets:
5231
5250
}
5232
5251
}
5233
5252
5253
+ func TestCompletion_FileStructureMerged (t * testing.T ) {
5254
+ testCases := []struct {
5255
+ name string
5256
+ content string
5257
+ line uint32
5258
+ character uint32
5259
+ list * protocol.CompletionList
5260
+ }{
5261
+ {
5262
+ name : "include array item suggests attributes and file structure" ,
5263
+ content : `
5264
+ include:
5265
+ - ` ,
5266
+ line : 2 ,
5267
+ character : 4 ,
5268
+ list : & protocol.CompletionList {
5269
+ Items : []protocol.CompletionItem {
5270
+ {
5271
+ Label : "a.txt" ,
5272
+ Kind : types .CreateCompletionItemKindPointer (protocol .CompletionItemKindFile ),
5273
+ },
5274
+ {
5275
+ Label : "b" ,
5276
+ Kind : types .CreateCompletionItemKindPointer (protocol .CompletionItemKindFolder ),
5277
+ },
5278
+ {
5279
+ Label : "env_file" ,
5280
+ Detail : types .CreateStringPointer ("array or string" ),
5281
+ Documentation : "Either a single string or a list of strings." ,
5282
+ TextEdit : textEdit ("env_file:" , 2 , 4 , 0 ),
5283
+ InsertTextMode : types .CreateInsertTextModePointer (protocol .InsertTextModeAsIs ),
5284
+ InsertTextFormat : types .CreateInsertTextFormatPointer (protocol .InsertTextFormatSnippet ),
5285
+ },
5286
+ {
5287
+ Label : "folder" ,
5288
+ Kind : types .CreateCompletionItemKindPointer (protocol .CompletionItemKindFolder ),
5289
+ },
5290
+ {
5291
+ Label : "path" ,
5292
+ Detail : types .CreateStringPointer ("array or string" ),
5293
+ Documentation : "Either a single string or a list of strings." ,
5294
+ TextEdit : textEdit ("path:" , 2 , 4 , 0 ),
5295
+ InsertTextMode : types .CreateInsertTextModePointer (protocol .InsertTextModeAsIs ),
5296
+ InsertTextFormat : types .CreateInsertTextFormatPointer (protocol .InsertTextFormatSnippet ),
5297
+ },
5298
+ {
5299
+ Label : "project_directory" ,
5300
+ Detail : types .CreateStringPointer ("string" ),
5301
+ Documentation : "Path to resolve relative paths set in the Compose file" ,
5302
+ TextEdit : textEdit ("project_directory: " , 2 , 4 , 0 ),
5303
+ InsertTextMode : types .CreateInsertTextModePointer (protocol .InsertTextModeAsIs ),
5304
+ InsertTextFormat : types .CreateInsertTextFormatPointer (protocol .InsertTextFormatSnippet ),
5305
+ },
5306
+ },
5307
+ },
5308
+ },
5309
+ }
5310
+
5311
+ dir := createFileStructure (t )
5312
+ composeFileURI := fmt .Sprintf ("file:///%v" , strings .TrimPrefix (filepath .ToSlash (filepath .Join (dir , "compose.yaml" )), "/" ))
5313
+
5314
+ for _ , tc := range testCases {
5315
+ t .Run (tc .name , func (t * testing.T ) {
5316
+ manager := document .NewDocumentManager ()
5317
+ doc := document .NewComposeDocument (manager , uri .URI (composeFileURI ), 1 , []byte (tc .content ))
5318
+ list , err := Completion (context .Background (), & protocol.CompletionParams {
5319
+ TextDocumentPositionParams : protocol.TextDocumentPositionParams {
5320
+ TextDocument : protocol.TextDocumentIdentifier {URI : composeFileURI },
5321
+ Position : protocol.Position {Line : tc .line , Character : tc .character },
5322
+ },
5323
+ }, manager , doc )
5324
+ require .NoError (t , err )
5325
+ require .Equal (t , tc .list , list )
5326
+ })
5327
+ }
5328
+ }
5329
+
5234
5330
func textEdit (newText string , line , character , prefixLength protocol.UInteger ) protocol.TextEdit {
5235
5331
return protocol.TextEdit {
5236
5332
NewText : newText ,
@@ -5246,3 +5342,31 @@ func textEdit(newText string, line, character, prefixLength protocol.UInteger) p
5246
5342
},
5247
5343
}
5248
5344
}
5345
+
5346
+ func createFileStructure (t * testing.T ) string {
5347
+ dir , err := os .MkdirTemp (os .TempDir (), fmt .Sprintf ("%v-%v" , t .Name (), time .Now ().UnixMilli ()))
5348
+ require .NoError (t , err )
5349
+ t .Cleanup (func () {
5350
+ require .NoError (t , os .RemoveAll (dir ))
5351
+ })
5352
+
5353
+ fileStructure := []struct {
5354
+ name string
5355
+ isDir bool
5356
+ }{
5357
+ {name : "a.txt" , isDir : false },
5358
+ {name : "b" , isDir : true },
5359
+ {name : "folder" , isDir : true },
5360
+ {name : "folder/subfile.txt" , isDir : false },
5361
+ }
5362
+ for _ , entry := range fileStructure {
5363
+ if entry .isDir {
5364
+ require .NoError (t , os .Mkdir (filepath .Join (dir , entry .name ), 0755 ))
5365
+ } else {
5366
+ f , err := os .Create (filepath .Join (dir , entry .name ))
5367
+ require .NoError (t , err )
5368
+ require .NoError (t , f .Close ())
5369
+ }
5370
+ }
5371
+ return dir
5372
+ }
0 commit comments