cuelang.org/go@v0.10.1/internal/golangorgx/gopls/file/kind.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package file 6 7 import "fmt" 8 9 // Kind describes the kind of the file in question. 10 // It can be one of Go,mod, Sum, or Tmpl. 11 type Kind int 12 13 const ( 14 // UnknownKind is a file type we don't know about. 15 UnknownKind = Kind(iota) 16 17 // Go is a Go source file. 18 Go 19 // Mod is a go.mod file. 20 Mod 21 // Sum is a go.sum file. 22 Sum 23 // Tmpl is a template file. 24 Tmpl 25 // Work is a go.work file. 26 Work 27 // CUE is a CUE source file 28 CUE 29 ) 30 31 func (k Kind) String() string { 32 switch k { 33 case Go: 34 return "go" 35 case Mod: 36 return "go.mod" 37 case Sum: 38 return "go.sum" 39 case Tmpl: 40 return "tmpl" 41 case Work: 42 return "go.work" 43 case CUE: 44 return "cue" 45 default: 46 return fmt.Sprintf("internal error: unknown file kind %d", k) 47 } 48 } 49 50 // KindForLang returns the file kind associated with the given language ID 51 // (from protocol.TextDocumentItem.LanguageID), or UnknownKind if the language 52 // ID is not recognized. 53 func KindForLang(langID string) Kind { 54 switch langID { 55 case "go": 56 return Go 57 case "go.mod": 58 return Mod 59 case "go.sum": 60 return Sum 61 case "tmpl", "gotmpl": 62 return Tmpl 63 case "go.work": 64 return Work 65 case "cue": 66 return CUE 67 default: 68 return UnknownKind 69 } 70 }