Skip to content

Commit 4d4b4f5

Browse files
committed
better import hover
1 parent 7824d42 commit 4d4b4f5

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

handlers/hover.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/DDP-Projekt/DDPLS/log"
1212
"github.com/DDP-Projekt/Kompilierer/src/ast"
1313
"github.com/DDP-Projekt/Kompilierer/src/ddppath"
14+
"github.com/DDP-Projekt/Kompilierer/src/ddptypes"
1415
"github.com/DDP-Projekt/Kompilierer/src/token"
1516
"github.com/tliron/glsp"
1617
protocol "github.com/tliron/glsp/protocol_3_16"
@@ -190,16 +191,50 @@ func (h *hoverVisitor) VisitStructLiteral(e *ast.StructLiteral) ast.VisitResult
190191

191192
// TODO: list all public decls
192193
func (h *hoverVisitor) VisitImportStmt(stmt *ast.ImportStmt) ast.VisitResult {
193-
if stmt.Module == nil || stmt.Module.Comment == nil {
194+
if stmt.Module == nil {
194195
return ast.VisitBreak
195196
}
196197

197-
comment := trimComment(stmt.Module.Comment)
198+
comment := getCommentDisplayString(stmt.Module.Comment)
199+
200+
variableSection := strings.Builder{}
201+
functionSection := strings.Builder{}
202+
structSection := strings.Builder{}
203+
204+
for _, decl := range stmt.Module.PublicDecls {
205+
switch decl := decl.(type) {
206+
case *ast.VarDecl:
207+
switch decl.Type.Gender() {
208+
case ddptypes.MASKULIN:
209+
variableSection.WriteString("Den ")
210+
case ddptypes.FEMININ:
211+
variableSection.WriteString("Die ")
212+
case ddptypes.NEUTRUM:
213+
variableSection.WriteString("Das ")
214+
}
215+
216+
variableSection.WriteString(decl.Type.String() + " " + decl.Name() + ".\n")
217+
case *ast.FuncDecl:
218+
functionSection.WriteString(fmt.Sprintf("Die Funktion %s.\n", decl.Name()))
219+
case *ast.StructDecl:
220+
structSection.WriteString(fmt.Sprintf("Die Kombination %s.\n", decl.Name()))
221+
}
222+
}
223+
224+
result := fmt.Sprintf(
225+
"%s\n\n%s deklariert:\n\n```ddp\n%s\n%s\n%s\n```\n",
226+
comment,
227+
h.getHoverFilePath(stmt.Module.FileName),
228+
structSection.String(),
229+
variableSection.String(),
230+
functionSection.String(),
231+
)
232+
198233
pRange := helper.ToProtocolRange(stmt.GetRange())
199234
h.hover = &protocol.Hover{
200235
Contents: protocol.MarkupContent{
201-
Kind: protocol.MarkupKindPlainText,
202-
Value: comment,
236+
Kind: protocol.MarkupKindMarkdown,
237+
Value: result,
203238
},
204239
Range: &pRange,
205240
}

0 commit comments

Comments
 (0)