Skip to content
Permalink
Browse files

Improve handling of improperly formatted docs().

This prevents the vscode extension and json-api mode from entirely breaking when given an extension with bad docs, and gives a more helpful message in vscode.
  • Loading branch information...
PseudoKnight committed Sep 6, 2019
1 parent 4d123ef commit 62e6867eec7c36eaaa0bf2667dd51b588d6be5b6
@@ -727,7 +727,7 @@ public EventDocInfo(String docs, String eventName) {
mutability.add(new MutabilityData(d[0], d.length > 1 ? d[1] : ""));
}
} else {
throw new RuntimeException("Invalid data from " + eventName + ": " + docs);
throw new IllegalArgumentException("Invalid docs formatting for " + eventName + ": \"" + docs + "\"");
}
}
}
@@ -772,7 +772,7 @@ public DocInfo(String doc) {
extendedDesc = parts[1].trim();
}
} else {
throw new IllegalArgumentException("Could not generate DocInfo from string: " + doc);
throw new IllegalArgumentException("Could not generate DocInfo from string: \"" + doc + "\"");
}
args = originalArgs.replaceAll("\\|", "<hr />").replaceAll("\\[(.*?)\\]", "<strong>[</strong>$1<strong>]</strong>");
}
@@ -73,8 +73,13 @@ public static void main(String[] args) {
for(FunctionBase f : FunctionList.getFunctionList(Platforms.INTERPRETER_JAVA, null)) {
if(f instanceof Function) {
Function ff = (Function) f;
DocGen.DocInfo di;
try {
di = new DocGen.DocInfo(ff.docs());
} catch (IllegalArgumentException ex) {
continue;
}
Map<String, Object> function = new TreeMap<>();
DocGen.DocInfo di = new DocGen.DocInfo(ff.docs());
function.put("name", ff.getName());
function.put("ret", di.ret);
function.put("args", di.originalArgs);
@@ -127,9 +132,14 @@ public static void main(String[] args) {
Map<String, Map<String, Object>> events = new TreeMap<>();
for(Event e : EventList.GetEvents()) {
try {
DocGen.EventDocInfo edi;
try {
edi = new DocGen.EventDocInfo(e.docs(), e.getName());
} catch (IllegalArgumentException ex) {
continue;
}
Map<String, Object> event = new TreeMap<>();
event.put("name", e.getName());
DocGen.EventDocInfo edi = new DocGen.EventDocInfo(e.docs(), e.getName());
event.put("desc", edi.description);
Map<String, String> ed = new TreeMap<>();
for(DocGen.EventDocInfo.EventData edd : edi.eventData) {
@@ -351,10 +351,17 @@ public void connect(LanguageClient client) {
if(fb.getClass().getAnnotation(hide.class) != null) {
continue;
}
DocGen.DocInfo di;
try {
di = new DocGen.DocInfo(fb.docs());
} catch (IllegalArgumentException ex) {
MSLog.GetLogger().Log(LANGSERVLOGTAG, LogLevel.ERROR, "Error parsing function \""
+ fb.getName() + "\". " + ex.getMessage(), Target.UNKNOWN);
continue;
}
CompletionItem ci = new CompletionItem(fb.getName());
// ci.setCommitCharacters(Arrays.asList("("));
ci.setKind(CompletionItemKind.Function);
DocGen.DocInfo di = new DocGen.DocInfo(fb.docs());
ci.setDetail(di.ret);
ci.setDocumentation(di.originalArgs + "\n\n" + di.desc
+ (di.extendedDesc == null ? "" : "\n\n" + di.extendedDesc));
@@ -366,10 +373,16 @@ public void connect(LanguageClient client) {
{
List<CompletionItem> list = new ArrayList<>();
for(Event e : EventList.GetEvents()) {
final DocGen.EventDocInfo edi;
try {
edi = new DocGen.EventDocInfo(e.docs(), e.getName());
} catch (IllegalArgumentException ex) {
MSLog.GetLogger().Log(LANGSERVLOGTAG, LogLevel.ERROR, ex.getMessage(), Target.UNKNOWN);
continue;
}
CompletionItem ci = new CompletionItem(e.getName());
ci.setCommitCharacters(Arrays.asList("'", "\""));
ci.setKind(CompletionItemKind.Function);
final DocGen.EventDocInfo edi = new DocGen.EventDocInfo(e.docs(), e.getName());
ci.setDetail("Event Type");
StringBuilder description = new StringBuilder();
description.append(edi.description).append("\n");

0 comments on commit 62e6867

Please sign in to comment.
You can’t perform that action at this time.