github.com/getgauge/gauge@v1.6.9/api/lang/completionTags.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package lang 8 9 import ( 10 "strings" 11 12 "github.com/sourcegraph/go-langserver/pkg/lsp" 13 ) 14 15 func tagsCompletion(line string, pLine string, params lsp.TextDocumentPositionParams) (interface{}, error) { 16 list := completionList{IsIncomplete: false, Items: []completionItem{}} 17 suffix, editRange := getTagsEditRange(line, pLine, params.Position) 18 for _, t := range provider.Tags() { 19 item := completionItem{ 20 InsertTextFormat: text, 21 CompletionItem: lsp.CompletionItem{ 22 SortText: "a" + t, 23 Label: t, 24 FilterText: t + suffix, 25 Detail: tag, 26 Kind: lsp.CIKVariable, 27 TextEdit: &lsp.TextEdit{Range: editRange, NewText: " " + t + suffix}, 28 }, 29 } 30 list.Items = append(list.Items, item) 31 } 32 return list, nil 33 } 34 35 func getTagsEditRange(line, pLine string, position lsp.Position) (string, lsp.Range) { 36 var editRange lsp.Range 37 suffix := emptyString 38 commaIndex := strings.LastIndex(pLine, comma) 39 colonIndex := strings.LastIndex(pLine, colon) 40 if commaIndex > colonIndex { 41 editRange = getEditRange(commaIndex, position, pLine, line, comma) 42 } else { 43 editRange = getEditRange(colonIndex, position, pLine, line, comma) 44 } 45 if len(line) >= position.Character+1 && len(line) != editRange.End.Character { 46 suffix = comma 47 } 48 return suffix, editRange 49 }