Skip to content

Commit

Permalink
improved outline view
Browse files Browse the repository at this point in the history
  • Loading branch information
peq committed Sep 6, 2018
1 parent 2f68a45 commit c7f7217
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -52,23 +51,29 @@ private void addSymbolsForPackage(List<DocumentSymbol> result, WPackage p) {
String name = p.getName();
result.add(makeDocumentSymbol(p, SymbolKind.Package, name, children));
for (WEntity e : p.getElements()) {
addSymbolsForEntity(children, name, e);
addSymbolsForEntity(children, e);
}
}

@NotNull
private DocumentSymbol makeDocumentSymbol(Element p, SymbolKind kind, String name, List<DocumentSymbol> children) {
return new DocumentSymbol(name, kind, Convert.range(p), Convert.errorRange(p), "detail", children);
String detail = null;
if (p instanceof AstElementWithParameters) {
detail = "(" + HoverInfo.getParameterString((AstElementWithParameters) p) + ")";
}
return new DocumentSymbol(name, kind, Convert.range(p), Convert.errorRange(p), detail, children);
}

private void addSymbolsForEntity(List<DocumentSymbol> result, String containerName, WEntity e) {
private void addSymbolsForEntity(List<DocumentSymbol> result, WEntity e) {
e.match(new WEntity.MatcherVoid() {
private void add(String name, SymbolKind kind) {
result.add(makeDocumentSymbol(e, kind, name, Collections.emptyList()));
add(name, kind, Collections.emptyList());
}

private void add(String name, SymbolKind kind, List<DocumentSymbol> children) {
result.add(makeDocumentSymbol(e, kind, name, children));
if (!e.attrSource().isArtificial()) {
result.add(makeDocumentSymbol(e, kind, name, children));
}
}

@Override
Expand All @@ -87,10 +92,10 @@ public void case_InterfaceDef(InterfaceDef interfaceDef) {
List<DocumentSymbol> children = new ArrayList<>();
add(name, SymbolKind.Interface, children);
for (FuncDef f : interfaceDef.getMethods()) {
addSymbolsForEntity(children, containerName + "." + name, f);
addSymbolsForEntity(children, f);
}
for (GlobalVarDef v : interfaceDef.getVars()) {
addSymbolsForEntity(children, containerName + "." + name, v);
addSymbolsForEntity(children, v);
}
}

Expand Down Expand Up @@ -146,19 +151,25 @@ public void case_ModuleDef(ModuleDef moduleDef) {
case_ClassOrModule(moduleDef);
}

public void case_ClassOrModule(ClassOrModule moduleDef) {
String name = moduleDef.getName();
public void case_ClassOrModule(ClassOrModule def) {
String name = def.getName();
List<DocumentSymbol> children = new ArrayList<>();
add(name, SymbolKind.Class, children);
for (ClassDef c : moduleDef.getInnerClasses()) {
addSymbolsForEntity(children, containerName + "." + name, c);
for (ClassDef c : def.getInnerClasses()) {
addSymbolsForEntity(children, c);
}
for (FuncDef f : moduleDef.getMethods()) {
addSymbolsForEntity(children, containerName + "." + name, f);
for (FuncDef f : def.getMethods()) {
addSymbolsForEntity(children, f);
}
for (GlobalVarDef v : moduleDef.getVars()) {
addSymbolsForEntity(children, containerName + "." + name, v);
for (GlobalVarDef v : def.getVars()) {
addSymbolsForEntity(children, v);
}
for (ConstructorDef c : def.getConstructors()) {
if (!c.attrSource().isArtificial()) {
children.add(makeDocumentSymbol(c, SymbolKind.Constructor, "construct", Collections.emptyList()));
}
}

}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ static String descriptionString(Element n) {
return res.toString().trim();
}

public static String getParameterString(AstElementWithParameters f) {
StringBuilder descrhtml = new StringBuilder();
boolean first = true;
for (WParameter p : f.getParameters()) {
if (!first) {
descrhtml.append(", ");
}
descrhtml.append(type(p.attrTyp())).append(" ").append(p.getName());
first = false;
}
return descrhtml.toString();
}

private static String type(WurstType wurstType) {
return wurstType.toString();
}

static class Description implements Element.Matcher<List<Either<String, MarkedString>>> {

public List<Either<String, MarkedString>> description(FunctionDefinition f) {
Expand Down Expand Up @@ -95,19 +112,6 @@ public List<Either<String, MarkedString>> description(FunctionDefinition f) {
return result;
}

public String getParameterString(AstElementWithParameters f) {
StringBuilder descrhtml = new StringBuilder();
boolean first = true;
for (WParameter p : f.getParameters()) {
if (!first) {
descrhtml.append(", ");
}
descrhtml.append(type(p.attrTyp())).append(" ").append(p.getName());
first = false;
}
return descrhtml.toString();
}

private static String nearestScopeName(Element n) {
if (n.attrNearestNamedScope() != null) {
return Utils.printElement(n.attrNearestNamedScope());
Expand Down Expand Up @@ -326,10 +330,6 @@ private List<Either<String, MarkedString>> string(String s) {
return Collections.singletonList(Either.forLeft(s));
}

private String type(WurstType wurstType) {
return wurstType.toString();
}

@Override
public List<Either<String, MarkedString>> case_StmtForRangeDown(StmtForRangeDown s) {
return string("Do something for all " + s.getLoopVar().getName() + " counting from _ down to _");
Expand Down

0 comments on commit c7f7217

Please sign in to comment.