Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MixinExtras expressions #2274

Merged
merged 110 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
5503d8f
Start on MixinExtras Expression language
Earthcomputer Jan 18, 2024
a9f66e6
MEExpression color settings page
Earthcomputer Jan 20, 2024
3b4a2bf
MEExpression annotator
Earthcomputer Jan 20, 2024
445bc57
MEExpression brace matcher and quote handler
Earthcomputer Jan 20, 2024
387f06c
Switch LHS of MEExpression assignmentExpression to themselves be cert…
Earthcomputer Jan 20, 2024
8e6a686
MEExpression language injection inside @Expression
Earthcomputer Jan 20, 2024
4c5e544
Fix formatting and licenses
Earthcomputer Jan 20, 2024
baa19de
Merge branch 'dev' into mixinextras-expression
Earthcomputer Jan 22, 2024
73c065a
Add MIXINEXTRAS:EXPRESSION injection point and add @Expression annota…
Earthcomputer Jan 22, 2024
226a593
Merge branch 'dev' into mixinextras-expression
Earthcomputer Jan 24, 2024
acce47e
Fix licenser errors
Earthcomputer Jan 24, 2024
2424c95
Add new ME expression features
Earthcomputer Jan 25, 2024
67b8365
Implement MixinExtras expression collect visitor
Earthcomputer Feb 3, 2024
25d79fa
Merge branch 'dev' into mixinextras-expression
Earthcomputer Feb 4, 2024
5f5bbd5
Fix cast expressions
Earthcomputer Feb 4, 2024
4f75339
Simple best-effort source matching for ME expressions
Earthcomputer Feb 6, 2024
36c7ff9
Fix name expression source matching
Earthcomputer Feb 6, 2024
0ff7c74
Fix MEName.isWildcard
Earthcomputer Feb 6, 2024
d0312b4
Fix MELitExpression source matching
Earthcomputer Feb 6, 2024
ff6cdbc
operationSign - operationTokenType
Earthcomputer Feb 6, 2024
cfe911a
Add built-in definitions
Earthcomputer Feb 7, 2024
226fdaa
Update MixinExtras
Earthcomputer Feb 7, 2024
35102d2
Start with ME definition references
Earthcomputer Feb 11, 2024
86d8b34
Attempt to overhaul ME expression injection
Earthcomputer Feb 12, 2024
fd06864
Some fixes to the new injection + navigation
Earthcomputer Feb 13, 2024
4e8c8cf
Merge branch 'dev' into mixinextras-expression
Earthcomputer Mar 7, 2024
ba6b6b5
MixinExtras: Add handler signature support for expressions. (#2244)
LlamaLad7 Mar 7, 2024
c5fdbd2
Partially fix ME definition renaming
Earthcomputer Mar 8, 2024
bdb3e9f
Attempt to get inplace rename refactoring to work (it doesn't)
Earthcomputer Mar 9, 2024
d8a45c8
MixinExtras: Use expression-suggested parameter names if they're pres…
LlamaLad7 Mar 10, 2024
69ff93f
Fix MEExpressionInjector. Rename refactoring works!
Earthcomputer Mar 10, 2024
1838363
Suppress deprecation warning
Earthcomputer Mar 10, 2024
daffb72
ME expression `@Definition` find usages
Earthcomputer Mar 10, 2024
37ef16c
Fix/expressions int like types (#2261)
LlamaLad7 Mar 10, 2024
8c2eea1
Add simple keyword completion to ME expressions
Earthcomputer Mar 11, 2024
6b83a7c
Why didn't my local ktlint tell me about these
Earthcomputer Mar 11, 2024
8665190
Store whether a declaration is a type in the ME PSI
Earthcomputer Mar 11, 2024
946a2ad
Add completions for items that already have a definition
Earthcomputer Mar 11, 2024
43cc4c9
Extract some ME expression matching into its own class, and cache som…
Earthcomputer Mar 12, 2024
df388fe
Remove some debug code
Earthcomputer Mar 12, 2024
e520269
First attempt at bytecode-based completion (it's broken)
Earthcomputer Mar 14, 2024
02c8ba4
Bytecode-based completion fixes
Earthcomputer Mar 14, 2024
ee82630
Add new definition annotations below existing definition annotations,…
Earthcomputer Mar 14, 2024
21cd38c
Fix cursor offset
Earthcomputer Mar 15, 2024
11ecf75
Add utilities to textify various ASM nodes
Earthcomputer Mar 18, 2024
a603be1
Add expression variants, to allow MixinExtras to match expressions as…
Earthcomputer Mar 18, 2024
2323f54
Merge two expression types into a single MENewExpression, improve ME …
Earthcomputer Mar 18, 2024
6f12b1d
Add better completion tail types
Earthcomputer Mar 19, 2024
a6aac8c
Fix completion not working inside of constructors
Earthcomputer Mar 19, 2024
c5ee3d0
Add errors/warnings for unused and unresolved definitions, and highli…
Earthcomputer Mar 19, 2024
373a0cf
Split MatchUtil into CompletionUtil
Earthcomputer Mar 20, 2024
9d3ce10
Fold @At.target for definition completions
Earthcomputer Mar 20, 2024
a69e3ee
Local variable completions
Earthcomputer Mar 20, 2024
24b5596
Some fixes to local variable completion
Earthcomputer Mar 20, 2024
73f6b41
Fix can-be-implicit locals with inaccessible types not showing template
Earthcomputer Mar 20, 2024
dbeb5ef
Show field and method types in completion list
Earthcomputer Mar 20, 2024
1b01e28
Add completion tests, and make some fixes to completion
Earthcomputer Mar 22, 2024
d782821
Fix folding on completion
Earthcomputer Mar 24, 2024
e43c74d
Refactor mcdev settings, move shadow setting into a project setting
Earthcomputer Mar 24, 2024
166bfaf
Add setting for position of @Definition relative to @Expression
Earthcomputer Mar 24, 2024
d586b52
Add folding for @Definitions
Earthcomputer Mar 25, 2024
efb945e
Fix array literal input completion
Earthcomputer Mar 26, 2024
3380ca1
Fix ktlint
Earthcomputer Mar 26, 2024
c5d31c0
Relax uniqueness in ME expression completions
Earthcomputer Mar 29, 2024
0517103
Initial switch from @Definition.at to field and method
Earthcomputer Mar 29, 2024
56e0e6e
Fix tests
Earthcomputer Mar 29, 2024
e81c885
Add references to @Definition.field and method
Earthcomputer Mar 29, 2024
c43ff4a
Add folding to @Definition.field and method
Earthcomputer Mar 29, 2024
a28e49e
Add comments to MEExpressionCompletionUtil to explain the completion …
Earthcomputer Mar 30, 2024
3fe87de
Fix @Local.type extraction
Earthcomputer Mar 30, 2024
77bcf22
Add string literal completion for ME expressions
Earthcomputer Mar 31, 2024
b4f511b
Fix @Local.type for source matching too
Earthcomputer Mar 31, 2024
2f977ab
Fix parsing of multiple @Expression annotations in a single modifier …
Earthcomputer Mar 31, 2024
a04e2f6
Merge branch 'dev' into mixinextras-expression
Earthcomputer Apr 4, 2024
4063f09
Format MEExpressionLexer.flex
Earthcomputer Apr 5, 2024
8bb9eb1
Better handle parenthesized expressions in Java source matching
Earthcomputer Apr 5, 2024
8770366
Add method reference expressions
Earthcomputer Apr 6, 2024
39e8062
Fix presentable name of method reference completions
Earthcomputer Apr 7, 2024
45c192a
Override matches(Handle) for method MemberDefinition
Earthcomputer Apr 7, 2024
cec4f29
Update MixinExtras and don't assume that instructions are part of the…
Earthcomputer Apr 10, 2024
175db4f
Wrap expanded instructions in a custom type to prevent them accidenta…
Earthcomputer Apr 11, 2024
b85cc23
Fix IdentityHashMap with VirtualInsn keys
Earthcomputer Apr 12, 2024
7255353
Update MixinExtras
Earthcomputer Apr 13, 2024
87841dc
Fix completion of new expressions with new MixinExtras update
Earthcomputer Apr 14, 2024
d93dd13
Update MixinExtras, fixes compound instructions
Earthcomputer Apr 14, 2024
ab50622
New: Add support for string concat expressions in MixinExtras. (#2281)
LlamaLad7 Apr 16, 2024
5c1cd92
Address PR comments
Earthcomputer Apr 19, 2024
7b07722
Merge remote-tracking branch 'refs/remotes/original/dev' into mixinex…
LlamaLad7 Jul 2, 2024
3ecde2d
MixinExtras Expressions: Migrate to Expressions library.
LlamaLad7 Jul 2, 2024
d8a9f83
Fix: Resolve being unable to get the descriptor for some complex types.
LlamaLad7 Jul 2, 2024
c88fd70
MixinExtras Expressions: Recreate `ClassInfo#getCommonSuperClassOrInt…
LlamaLad7 Jul 2, 2024
a316086
MixinExtras: Fix completion confidence.
LlamaLad7 Jul 3, 2024
b301781
Expressions: Autocomplete `method`s and `field`s using flows not inst…
LlamaLad7 Jul 3, 2024
a9d6263
Expressions: Autocomplete `method`s for method references.
LlamaLad7 Jul 3, 2024
91c75c7
Expressions: A class constant is an expression.
LlamaLad7 Jul 4, 2024
2d797a9
Expressions: Show instantiation desc in autocomplete.
LlamaLad7 Jul 4, 2024
72f389d
Expressions: Make completions always unique to stop them being filtered.
LlamaLad7 Jul 4, 2024
5c32ef9
Expressions: Overhaul array completions.
LlamaLad7 Jul 4, 2024
d139d74
Expressions: Fix super call completions.
LlamaLad7 Jul 4, 2024
a4769e3
Expressions: Confidently suggest completions after `::`.
LlamaLad7 Jul 4, 2024
95fab6f
Expressions: Add intention action to define unresolved identifiers.
LlamaLad7 Jul 4, 2024
e654d59
Expressions: Fix `@Local`s not properly handling compound insns.
LlamaLad7 Jul 4, 2024
a46940c
Refactor: Add `project` as parameter to `MEExpressionCompletionUtil.a…
LlamaLad7 Jul 9, 2024
8a97cb5
Merge pull request #2327 from LlamaLad7/fix/llamas-expressions-fixes-v2
Earthcomputer Jul 9, 2024
75eec45
Merge branch 'refs/heads/dev' into update/llamas-expression-updates
LlamaLad7 Jul 9, 2024
5e2cbea
Merge pull request #2328 from LlamaLad7/update/expressions-dev-merge
Earthcomputer Jul 10, 2024
a7298d3
Use maven central MixinExtras library
Earthcomputer Jul 12, 2024
f929ae0
Merge branch 'refs/heads/dev' into mixinextras-expression
Earthcomputer Jul 12, 2024
9d1ec2f
Remove reference to light service in plugin.xml
Earthcomputer Jul 12, 2024
ce61bcf
Use ReentrantReadWriteLock.read and write extension functions
Earthcomputer Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ repositories {
}
}
mavenCentral()
maven("https://repo.spongepowered.org/maven/")
}

dependencies {
// Add tools.jar for the JDI API
implementation(files(Jvm.current().toolsJar))

implementation(libs.mixinExtras.expressions)
testLibs(libs.mixinExtras.common)
implementation("org.ow2.asm:asm-util:9.3")
Earthcomputer marked this conversation as resolved.
Show resolved Hide resolved

// Kotlin
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
Expand Down Expand Up @@ -198,6 +203,7 @@ intellij {
"Kotlin",
"org.toml.lang:$pluginTomlVersion",
"ByteCodeViewer",
"org.intellij.intelliLang",
"properties",
// needed dependencies for unit tests
"junit"
Expand Down Expand Up @@ -363,6 +369,9 @@ val generateNbttParser by parser("NbttParser", "com/demonwav/mcdev/nbt/lang/gen"
val generateLangLexer by lexer("LangLexer", "com/demonwav/mcdev/translations/lang/gen")
val generateLangParser by parser("LangParser", "com/demonwav/mcdev/translations/lang/gen")

val generateMEExpressionLexer by lexer("MEExpressionLexer", "com/demonwav/mcdev/platform/mixin/expression/gen")
val generateMEExpressionParser by parser("MEExpressionParser", "com/demonwav/mcdev/platform/mixin/expression/gen")

val generateTranslationTemplateLexer by lexer(
"TranslationTemplateLexer",
"com/demonwav/mcdev/translations/template/gen"
Expand All @@ -381,6 +390,8 @@ val generate by tasks.registering {
generateNbttParser,
generateLangLexer,
generateLangParser,
generateMEExpressionLexer,
generateMEExpressionParser,
generateTranslationTemplateLexer,
)
}
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coroutines-jdk8 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8", ve
coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }

mappingIo = "net.fabricmc:mapping-io:0.2.1"
mixinExtras-expressions = "io.github.llamalad7:mixinextras-expressions:0.0.1"

# GrammarKit
jflex-lib = "org.jetbrains.idea:jflex:1.7.0-b7f882a"
Expand Down Expand Up @@ -40,6 +41,8 @@ junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "jun
junit-entine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform" }

mixinExtras-common = "io.github.llamalad7:mixinextras-common:0.5.0-beta.1"

[bundles]
coroutines = ["coroutines-core", "coroutines-jdk8", "coroutines-swing"]
asm = ["asm", "asm-tree", "asm-analysis"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2024 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.mixintestdata.meExpression;

import java.util.ArrayList;
import java.util.stream.Stream;

public class MEExpressionTestData {
private static final SynchedData<Integer> STINGER_COUNT = null;
private SynchedDataManager synchedData;

public void complexFunction() {
int one = 1;
String local1 = "Hello";
String local2 = "World";

System.out.println(new StringBuilder(local1).append(", ").append(local2));
System.out.println(one);

new ArrayList<>(10);

InaccessibleType varOfInaccessibleType = new InaccessibleType();
acceptInaccessibleType(varOfInaccessibleType);
noArgMethod();

String[] strings1 = new String[] { local1, local2 };
String[] strings2 = new String[one];

Stream.empty().map(this::nonStaticMapper).map(MEExpressionTestData::staticMapper).map(ConstructedByMethodReference::new);
}

private static void acceptInaccessibleType(InaccessibleType type) {
}

private static void noArgMethod() {
}

public int getStingerCount() {
return (Integer) this.synchedData.get(STINGER_COUNT);
}

private Object nonStaticMapper(Object arg) {
return arg;
}

private static Object staticMapper(Object arg) {
return arg;
}

private static class InaccessibleType {

}

public static class SynchedDataManager {
public <V> V get(SynchedData<V> data) {
return null;
}
}

public static class SynchedData<V> {
}

public static class ConstructedByMethodReference {
public ConstructedByMethodReference(Object bar) {}
}
}
146 changes: 146 additions & 0 deletions src/main/grammars/MEExpressionLexer.flex
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2024 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.platform.mixin.expression;

import com.demonwav.mcdev.platform.mixin.expression.gen.psi.MEExpressionTypes;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.TokenType;

%%

%public
%class MEExpressionLexer
%implements FlexLexer
%function advance
%type IElementType
Earthcomputer marked this conversation as resolved.
Show resolved Hide resolved

%state STRING

%unicode

WHITE_SPACE = [\ \n\t\r]
RESERVED = assert|break|case|catch|const|continue|default|else|finally|for|goto|if|switch|synchronized|try|while|yield|_
WILDCARD = "?"
NEW = new
INSTANCEOF = instanceof
BOOL_LIT = true|false
NULL_LIT = null
DO = do
RETURN = return
THROW = throw
THIS = this
SUPER = super
CLASS = class
IDENTIFIER = [A-Za-z_][A-Za-z0-9_]*
INT_LIT = ( [0-9]+ | 0x[0-9a-fA-F]+ )
DEC_LIT = [0-9]*\.[0-9]+
PLUS = "+"
MINUS = -
MULT = "*"
DIV = "/"
MOD = %
BITWISE_NOT = "~"
DOT = "."
COMMA = ,
LEFT_PAREN = "("
RIGHT_PAREN = ")"
LEFT_BRACKET = "["
RIGHT_BRACKET = "]"
LEFT_BRACE = "{"
RIGHT_BRACE = "}"
AT = @
SHL = <<
SHR = >>
USHR = >>>
LT = <
LE = <=
GT = >
GE = >=
EQ = ==
NE = "!="
BITWISE_AND = &
BITWISE_XOR = "^"
BITWISE_OR = "|"
ASSIGN = =
METHOD_REF = ::

STRING_TERMINATOR = '
STRING_ESCAPE = \\'|\\\\

%%

<YYINITIAL> {
{WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
{RESERVED} { return MEExpressionTypes.TOKEN_RESERVED; }
{WILDCARD} { return MEExpressionTypes.TOKEN_WILDCARD; }
{NEW} { return MEExpressionTypes.TOKEN_NEW; }
{INSTANCEOF} { return MEExpressionTypes.TOKEN_INSTANCEOF; }
{BOOL_LIT} { return MEExpressionTypes.TOKEN_BOOL_LIT; }
{NULL_LIT} { return MEExpressionTypes.TOKEN_NULL_LIT; }
{DO} { return MEExpressionTypes.TOKEN_DO; }
{RETURN} { return MEExpressionTypes.TOKEN_RETURN; }
{THROW} { return MEExpressionTypes.TOKEN_THROW; }
{THIS} { return MEExpressionTypes.TOKEN_THIS; }
{SUPER} { return MEExpressionTypes.TOKEN_SUPER; }
{CLASS} { return MEExpressionTypes.TOKEN_CLASS; }
{IDENTIFIER} { return MEExpressionTypes.TOKEN_IDENTIFIER; }
{INT_LIT} { return MEExpressionTypes.TOKEN_INT_LIT; }
{DEC_LIT} { return MEExpressionTypes.TOKEN_DEC_LIT; }
{PLUS} { return MEExpressionTypes.TOKEN_PLUS; }
{MINUS} { return MEExpressionTypes.TOKEN_MINUS; }
{MULT} { return MEExpressionTypes.TOKEN_MULT; }
{DIV} { return MEExpressionTypes.TOKEN_DIV; }
{MOD} { return MEExpressionTypes.TOKEN_MOD; }
{BITWISE_NOT} { return MEExpressionTypes.TOKEN_BITWISE_NOT; }
{DOT} { return MEExpressionTypes.TOKEN_DOT; }
{COMMA} { return MEExpressionTypes.TOKEN_COMMA; }
{LEFT_PAREN} { return MEExpressionTypes.TOKEN_LEFT_PAREN; }
{RIGHT_PAREN} { return MEExpressionTypes.TOKEN_RIGHT_PAREN; }
{LEFT_BRACKET} { return MEExpressionTypes.TOKEN_LEFT_BRACKET; }
{RIGHT_BRACKET} { return MEExpressionTypes.TOKEN_RIGHT_BRACKET; }
{LEFT_BRACE} { return MEExpressionTypes.TOKEN_LEFT_BRACE; }
{RIGHT_BRACE} { return MEExpressionTypes.TOKEN_RIGHT_BRACE; }
{AT} { return MEExpressionTypes.TOKEN_AT; }
{SHL} { return MEExpressionTypes.TOKEN_SHL; }
{SHR} { return MEExpressionTypes.TOKEN_SHR; }
{USHR} { return MEExpressionTypes.TOKEN_USHR; }
{LT} { return MEExpressionTypes.TOKEN_LT; }
{LE} { return MEExpressionTypes.TOKEN_LE; }
{GT} { return MEExpressionTypes.TOKEN_GT; }
{GE} { return MEExpressionTypes.TOKEN_GE; }
{EQ} { return MEExpressionTypes.TOKEN_EQ; }
{NE} { return MEExpressionTypes.TOKEN_NE; }
{BITWISE_AND} { return MEExpressionTypes.TOKEN_BITWISE_AND; }
{BITWISE_XOR} { return MEExpressionTypes.TOKEN_BITWISE_XOR; }
{BITWISE_OR} { return MEExpressionTypes.TOKEN_BITWISE_OR; }
{ASSIGN} { return MEExpressionTypes.TOKEN_ASSIGN; }
{METHOD_REF} { return MEExpressionTypes.TOKEN_METHOD_REF; }
{STRING_TERMINATOR} { yybegin(STRING); return MEExpressionTypes.TOKEN_STRING_TERMINATOR; }
}

<STRING> {
{STRING_ESCAPE} { return MEExpressionTypes.TOKEN_STRING_ESCAPE; }
{STRING_TERMINATOR} { yybegin(YYINITIAL); return MEExpressionTypes.TOKEN_STRING_TERMINATOR; }
[^'\\]+ { return MEExpressionTypes.TOKEN_STRING; }
}

[^] { return TokenType.BAD_CHARACTER; }
Loading
Loading