-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Vanusanik
committed
Feb 3, 2023
1 parent
2165225
commit e41b114
Showing
14 changed files
with
282 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 25 additions & 5 deletions
30
src/main/gen/com/en_circle/slt/plugin/lisp/LispParser.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/en_circle/slt/plugin/params/LispArgslist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.en_circle.slt.plugin.params; | ||
|
||
import com.en_circle.slt.plugin.SltBundle; | ||
import com.en_circle.slt.plugin.lisp.lisp.LispElement; | ||
import com.en_circle.slt.plugin.lisp.lisp.LispString; | ||
|
||
public class LispArgslist { | ||
|
||
private final String information; | ||
|
||
public LispArgslist(LispElement data) { | ||
if (data instanceof LispString str) { | ||
this.information = str.getValue(); | ||
} else { | ||
this.information = SltBundle.message("slt.argslist.error"); | ||
} | ||
} | ||
|
||
public String getInformation() { | ||
return information; | ||
} | ||
|
||
} |
130 changes: 130 additions & 0 deletions
130
src/main/java/com/en_circle/slt/plugin/params/SltParameterInfoHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.en_circle.slt.plugin.params; | ||
|
||
import com.en_circle.slt.plugin.lisp.LispParserUtil; | ||
import com.en_circle.slt.plugin.lisp.LispParserUtil.QuoteState; | ||
import com.en_circle.slt.plugin.lisp.psi.LispList; | ||
import com.en_circle.slt.plugin.lisp.psi.LispSexpr; | ||
import com.en_circle.slt.plugin.lisp.psi.LispSymbol; | ||
import com.en_circle.slt.plugin.services.lisp.LispEnvironmentService; | ||
import com.en_circle.slt.plugin.services.lisp.LispEnvironmentService.LispEnvironmentState; | ||
import com.en_circle.slt.plugin.swank.requests.Argslist; | ||
import com.en_circle.slt.tools.SltApplicationUtils; | ||
import com.intellij.lang.parameterInfo.CreateParameterInfoContext; | ||
import com.intellij.lang.parameterInfo.ParameterInfoHandler; | ||
import com.intellij.lang.parameterInfo.ParameterInfoUIContext; | ||
import com.intellij.lang.parameterInfo.UpdateParameterInfoContext; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.PsiWhiteSpace; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class SltParameterInfoHandler implements ParameterInfoHandler<LispList, LispArgslist> { | ||
|
||
@Override | ||
public @Nullable LispList findElementForParameterInfo(@NotNull CreateParameterInfoContext context) { | ||
LispList candidate = findElementAtOffset(context.getFile(), context.getOffset()); | ||
if (candidate != null) { | ||
if (LispEnvironmentService.getInstance(context.getProject()).getState() == LispEnvironmentState.READY) { | ||
LispSymbol symbol = getHead(candidate); | ||
if (symbol == null) | ||
return null; | ||
|
||
String packageName = LispParserUtil.getPackage(candidate); | ||
Object[] items = SltApplicationUtils.getAsyncResultNoThrow(context.getProject(), finishRequest -> Argslist | ||
.getArgslist(symbol.getName(), packageName, | ||
result -> finishRequest.accept(getCandidateObjects(result)))); | ||
if (items != null) { | ||
context.setItemsToShow(items); | ||
return candidate; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private LispSymbol getHead(LispList candidate) { | ||
if (candidate.getSexprList().size() > 0) { | ||
LispSexpr sexpr = candidate.getSexprList().get(0); | ||
if (sexpr.getDatum() != null && sexpr.getDatum().getCompoundSymbol() != null) { | ||
return sexpr.getDatum().getCompoundSymbol().getSymbol(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private Object[] getCandidateObjects(LispArgslist result) { | ||
return new Object[] { result }; | ||
} | ||
|
||
@Override | ||
public void showParameterInfo(@NotNull LispList element, @NotNull CreateParameterInfoContext context) { | ||
context.showHint(element, element.getTextRange().getStartOffset() + 1, this); | ||
} | ||
|
||
@Override | ||
public @Nullable LispList findElementForUpdatingParameterInfo(@NotNull UpdateParameterInfoContext context) { | ||
LispList candidate = findElementAtOffset(context.getFile(), context.getOffset()); | ||
if (candidate != null) { | ||
PsiElement current = context.getParameterOwner(); | ||
if (current == null || current == candidate) return candidate; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void updateParameterInfo(@NotNull LispList lispList, @NotNull UpdateParameterInfoContext context) { | ||
context.setParameterOwner(lispList); | ||
} | ||
|
||
@Override | ||
public void updateUI(LispArgslist p, @NotNull ParameterInfoUIContext context) { | ||
context.setupUIComponentPresentation(p.getInformation(), 0, 0, false, | ||
false, true, context.getDefaultParameterColor()); | ||
} | ||
|
||
private LispList findElementAtOffset(PsiFile file, int offset) { | ||
PsiElement element = file.findElementAt(offset); | ||
while (element == null || element instanceof PsiWhiteSpace) { | ||
element = file.findElementAt(offset--); | ||
} | ||
|
||
LispList l; | ||
if ((element instanceof LispList)) { | ||
l = (LispList) element; | ||
} else { | ||
l = PsiTreeUtil.getParentOfType(element, LispList.class); | ||
} | ||
|
||
if (l != null) { | ||
QuoteState quoteState = LispParserUtil.getQuoteState(l); | ||
if (quoteState == QuoteState.NO_STATE || quoteState == QuoteState.ERROR_STATE) { | ||
return l; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
// private LispSexpr @NotNull [] getActualParameters(@NotNull LispList o) { | ||
// List<LispSexpr> arguments = new ArrayList<>(); | ||
// QuoteState quoteState = LispParserUtil.getQuoteState(o); | ||
// if (quoteState == QuoteState.ERROR_STATE || quoteState == QuoteState.NO_STATE) { | ||
// for (int i=1; i<o.getSexprList().size(); i++) { | ||
// LispSexpr element = o.getSexprList().get(i); | ||
// LispSymbol symbol = PsiTreeUtil.getChildOfType(element, LispSymbol.class); | ||
// LispList list = PsiTreeUtil.getChildOfType(element, LispList.class); | ||
// if (list == null && symbol != null) { | ||
// if (symbol.getName() == null || !symbol.getName().startsWith(":")) { | ||
// arguments.add(element); | ||
// } | ||
// } else { | ||
// arguments.add(element); | ||
// } | ||
// } | ||
// } | ||
// | ||
// return arguments.toArray(new LispSexpr[0]); | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/en_circle/slt/plugin/swank/requests/Argslist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.en_circle.slt.plugin.swank.requests; | ||
|
||
import com.en_circle.slt.plugin.lisp.lisp.LispContainer; | ||
import com.en_circle.slt.plugin.lisp.lisp.LispSymbol; | ||
import com.en_circle.slt.plugin.params.LispArgslist; | ||
import com.en_circle.slt.plugin.swank.SlimeRequest; | ||
import com.en_circle.slt.plugin.swank.SwankPacket; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class Argslist extends SlimeRequest { | ||
|
||
public static SlimeRequest getArgslist(String symbol, String packageName, Callback callback) { | ||
return new Argslist(symbol, packageName, callback); | ||
} | ||
|
||
private final String symbol; | ||
private final String packageName; | ||
private final Callback callback; | ||
|
||
private Argslist(String symbol, String packageName, Callback callback) { | ||
this.symbol = symbol; | ||
this.packageName = packageName; | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public SwankPacket createPacket(BigInteger requestId) { | ||
return SwankPacket.argslist(symbol, packageName, requestId); | ||
} | ||
|
||
public void processReply(LispContainer data) { | ||
if (isOk(data)) { | ||
callback.onResult(new LispArgslist(data.getItems().get(1))); | ||
} | ||
} | ||
|
||
private boolean isOk(LispContainer data) { | ||
return data.getItems().size() > 0 && | ||
data.getItems().get(0) instanceof LispSymbol && | ||
":ok".equals(((LispSymbol) data.getItems().get(0)).getValue()); | ||
} | ||
|
||
public interface Callback { | ||
void onResult(LispArgslist result); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.