VSCode: Add support for methods in type body (#10560)

VSCode extension structure supports methods in type bodies.

![image](https://github.com/user-attachments/assets/f8b4771d-45c9-4884-89b6-9c884fe84a78)
This commit is contained in:
Pavel Marek 2024-07-18 08:43:23 +02:00 committed by GitHub
parent 27515c49d4
commit 154d5c0516
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import org.enso.compiler.core.EnsoParser;
import org.enso.compiler.core.IR;
import org.enso.compiler.core.ir.Function;
import org.enso.compiler.core.ir.module.scope.Definition;
import org.enso.compiler.core.ir.module.scope.definition.Method;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
@ -66,6 +67,11 @@ public final class EnsoStructure implements StructureProvider {
yield bldr;
}
case Function.Binding funcBinding -> {
var bldr = StructureProvider.newBuilder(funcBinding.name().name(), StructureElement.Kind.Method);
yield bldr;
}
case Method.Binding bind -> {
var bldr = StructureProvider.newBuilder(bind.methodName().name(), StructureElement.Kind.Method);
yield bldr;

View File

@ -5,6 +5,7 @@ import javax.swing.text.PlainDocument;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.netbeans.api.lsp.StructureElement;
import org.netbeans.api.lsp.StructureElement.Kind;
public class EnsoStructureTest {
@ -43,4 +44,34 @@ public class EnsoStructureTest {
assertEquals("It is a method", StructureElement.Kind.Method, root.get(0).getKind());
assertEquals("It is a method", "main", root.get(0).getName());
}
@Test
public void collectMethodInType() throws Exception {
var doc = new PlainDocument();
doc.insertString(0, """
type My_Type
my_method self = 42
""", null);
var s = new EnsoStructure();
var root = s.getStructure(doc);
assertEquals(1, root.size());
assertEquals("My_Type is class", Kind.Class, root.get(0).getKind());
var children = root.get(0).getChildren();
assertEquals("Has 1 child", 1, children.size());
assertEquals("my_method is method", Kind.Method, children.get(0).getKind());
}
@Test
public void collectExtensionMethod() throws Exception {
var doc = new PlainDocument();
doc.insertString(0, """
type My_Type
My_Type.extension_method self = 42
""", null);
var s = new EnsoStructure();
var root = s.getStructure(doc);
assertEquals(2, root.size());
assertEquals("My_Type is class", Kind.Class, root.get(0).getKind());
assertEquals("My_Type.extension_method is method", Kind.Method, root.get(1).getKind());
}
}