Skip to content

Commit

Permalink
#63
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vanusanik committed Mar 19, 2023
1 parent d993ca6 commit 5ba9457
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 0.5.0

### Added
- Hyperspec embedded in the tool window (requires internet connection to see obviously)

### Changes
- support for definitions under other expressions
- SltPlainTextSymbolCompletionContributor - to be used with git and such
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ You can also open this as a project in Intellij Idea.

## Planned features / goals

* [ ] Upload to marketplace when it has enough features
* [x] Upload to marketplace when it has enough features
* [x] Automatic indentation
* [x] REPL
* [x] Interactive debugging
* [x] Argument help (Ctrl+P)
* [x] Inspection
* [x] Basic inspection
* [ ] Actions
* [x] Actions
* [ ] Inspection eval
* [x] Breakpoints
* [x] Documentation
* [x] Hyperspec intergration
* [x] Macro expand in documentation
* Macro expand requires you to hover element twice for now
* [x] Find function by symbol name
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation("org.watertemplate:watertemplate-engine:1.2.2")
implementation("com.google.guava:guava:31.1-jre")
implementation("org.rauschig:jarchivelib:1.2.0")
implementation("org.abcl:abcl:1.8.0")
implementation("org.jsoup:jsoup:1.7.2")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.en_circle.slt.plugin;

import com.en_circle.slt.plugin.ui.SltHyperspecView;
import com.en_circle.slt.plugin.ui.SltUIService;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

public class SltHyperspecWindowFactory implements ToolWindowFactory, DumbAware {

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
{
SltHyperspecView hyperspecView = new SltHyperspecView(toolWindow);
ContentFactory contentFactory = ContentFactory.getInstance();
Content content = contentFactory.createContent(hyperspecView.getContent(),
SltBundle.message("slt.ui.clhs.title"), false);
toolWindow.getContentManager().addContent(content);

Disposer.register(SltUIService.getInstance(project), hyperspecView);
}
}

}
64 changes: 64 additions & 0 deletions src/main/java/com/en_circle/slt/plugin/actions/OpenCLHSAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.en_circle.slt.plugin.actions;

import com.en_circle.slt.plugin.SltCommonLispFileType;
import com.en_circle.slt.plugin.lisp.psi.LispSymbol;
import com.en_circle.slt.plugin.services.SltProjectService;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class OpenCLHSAction extends AnAction {

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor != null && event.getProject() != null) {
PsiFile file = PsiDocumentManager.getInstance(Objects.requireNonNull(editor.getProject())).getPsiFile(editor.getDocument());
if (file != null && SltCommonLispFileType.INSTANCE.equals(file.getFileType())) {
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
LispSymbol symbol = null;
if (element instanceof LispSymbol lispSymbol) {
symbol = lispSymbol;
} else {
symbol = PsiTreeUtil.getParentOfType(element, LispSymbol.class);
if (symbol == null) {
symbol = PsiTreeUtil.getChildOfType(element, LispSymbol.class);
}
}

if (symbol != null) {
SltProjectService.getInstance(editor.getProject())
.showCLHSSymbol(Objects.requireNonNull(symbol.getName()).toLowerCase());
}
}
}
}

@Override
public void update(@NotNull AnActionEvent event) {
event.getPresentation().setEnabledAndVisible(false);

Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor != null && event.getProject() != null) {
PsiFile file = PsiDocumentManager.getInstance(Objects.requireNonNull(editor.getProject())).getPsiFile(editor.getDocument());
if (file != null && SltCommonLispFileType.INSTANCE.equals(file.getFileType())) {
event.getPresentation().setEnabledAndVisible(true);
}
}
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.en_circle.slt.plugin.services;

import com.en_circle.slt.plugin.SltBundle;
import com.en_circle.slt.plugin.ui.SltHyperspecView;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import org.apache.commons.io.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URL;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

public class SltProjectService implements DumbAware {
private static final Logger log = LoggerFactory.getLogger(SltProjectService.class);

public static SltProjectService getInstance(Project project) {
return project.getService(SltProjectService.class);
}

private SltHyperspecView hyperspecView;
private Map<String, String> symbolRefMap = null;
private final Project project;

public SltProjectService(Project project) {
this.project = project;
ApplicationManager.getApplication().executeOnPooledThread(this::loadHyperspec);
}

private void loadHyperspec() {
try {
Map<String, String> symbolParseMap = new HashMap<>();

String base = "http://www.lispworks.com/documentation/HyperSpec/Front/";
String html = IOUtils.toString(new URL("http://www.lispworks.com/documentation/HyperSpec/Front/X_AllSym.htm"),
Charset.defaultCharset());
Document document = Jsoup.parse(html);
Elements links = document.select("a[href]");
for (Element link : links) {
if ("DEFINITION".equals(link.attr("REL"))) {
String ref = link.text();
String page = base + link.attr("HREF");
symbolParseMap.put(ref, page);
}
}

symbolRefMap = symbolParseMap;
} catch (Exception e) {
log.error(e.getMessage());
}
}

public void showCLHSSymbol(String symbolName) {
if (symbolRefMap != null) {
String url = symbolRefMap.get(symbolName);
if (url != null) {
ToolWindow toolWindow = ToolWindowManager.getInstance(project)
.getToolWindow("CLHS");
assert toolWindow != null;
toolWindow.show(() -> {
if (hyperspecView != null) {
hyperspecView.showUrl(url);
}
});
return;
}
}

Messages.showInfoMessage(String.format(SltBundle.message("slt.ui.clhs.nosymbol.message"), symbolName),
SltBundle.message("slt.ui.clhs.nosymbol.title"));
}

public void setHyperspecView(SltHyperspecView hyperspecView) {
this.hyperspecView = hyperspecView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import com.en_circle.slt.tools.SltApplicationUtils;
import com.google.common.collect.Lists;
import com.intellij.openapi.project.Project;
import com.intellij.util.Consumer;
import com.intellij.util.concurrency.FutureResult;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -96,10 +96,10 @@ private void refreshBatchedSymbols(BatchedSymbolRefreshAction action, Consumer<B
if (LispEnvironmentService.getInstance(project).getState() == LispEnvironmentState.READY) {
refreshSymbolsBatched(withoutDuplicity, onFinish);
} else {
onFinish.consume(true);
onFinish.accept(true);
}
} catch (Exception e) {
onFinish.consume(false);
onFinish.accept(false);
}
}

Expand Down Expand Up @@ -231,11 +231,11 @@ private void refreshSymbolsBatched(List<SymbolState> refreshStates, Consumer<Boo
}

if (requestFinished != null) {
requestFinished.consume(true);
requestFinished.accept(true);
}
}), false, () -> {
if (requestFinished != null) {
requestFinished.consume(false);
requestFinished.accept(false);
}
});
}
Expand Down
Loading

0 comments on commit 5ba9457

Please sign in to comment.