Skip to content

Commit 0ea1887

Browse files
committed
Removed unnecessary file types in go to definition and returned error on unknown file type
1 parent 7cda7b3 commit 0ea1887

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

ls/ls.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ type Config struct {
8888
}
8989

9090
var extToFileType = map[string]string{
91-
".ino": "arduino",
92-
".cpp": "cpp",
9391
".h": "cpp",
94-
".c": "c",
92+
".hpp": "cpp",
9593
}
9694

9795
var yellow = color.New(color.FgHiYellow)
@@ -1639,6 +1637,16 @@ type UnknownURIError struct {
16391637
URI lsp.DocumentURI
16401638
}
16411639

1640+
// UnknownFileExtensionError when a file extension isn't recognized
1641+
// and a file with it has to be opened.
1642+
type UnknownFileExtensionError struct {
1643+
extension string
1644+
}
1645+
16421646
func (e *UnknownURIError) Error() string {
16431647
return "Document is not available: " + e.URI.String()
16441648
}
1649+
1650+
func (e *UnknownFileExtensionError) Error() string {
1651+
return "Unknown file extension " + e.extension
1652+
}

ls/ls_ide_to_clang.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import (
2525
"go.bug.st/lsp/jsonrpc"
2626
)
2727

28-
func getFileType(filename string) string {
29-
ext := filepath.Ext(filename)
28+
func getFileType(ext string) string {
3029
if fileType, ok := extToFileType[ext]; ok {
3130
return fileType
3231
}
@@ -37,11 +36,12 @@ func (ls *INOLanguageServer) idePathToIdeURI(logger jsonrpc.FunctionLogger, inoP
3736
}
3837

3938
func makeTextDocumentItem(logger jsonrpc.FunctionLogger, path string) (lsp.TextDocumentItem, bool, error) {
39+
ext := filepath.Ext(path)
4040
filetype := getFileType(path)
41+
uri := lsp.NewDocumentURI(path)
4142
if filetype == "unknown" {
42-
return lsp.TextDocumentItem{}, false, nil
43+
return lsp.TextDocumentItem{URI: uri, LanguageID: filetype}, false, &UnknownFileExtensionError{ext}
4344
}
44-
uri := lsp.NewDocumentURI(path)
4545
languageId := filetype
4646
version := 0
4747

0 commit comments

Comments
 (0)