golang.org/x/tools/gopls@v0.15.3/internal/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 ) 28 29 func (k Kind) String() string { 30 switch k { 31 case Go: 32 return "go" 33 case Mod: 34 return "go.mod" 35 case Sum: 36 return "go.sum" 37 case Tmpl: 38 return "tmpl" 39 case Work: 40 return "go.work" 41 default: 42 return fmt.Sprintf("internal error: unknown file kind %d", k) 43 } 44 } 45 46 // KindForLang returns the file kind associated with the given language ID 47 // (from protocol.TextDocumentItem.LanguageID), or UnknownKind if the language 48 // ID is not recognized. 49 func KindForLang(langID string) Kind { 50 switch langID { 51 case "go": 52 return Go 53 case "go.mod": 54 return Mod 55 case "go.sum": 56 return Sum 57 case "tmpl", "gotmpl": 58 return Tmpl 59 case "go.work": 60 return Work 61 default: 62 return UnknownKind 63 } 64 }