serenadeai / serenade

Apache License 2.0
317 stars 57 forks source link

Four JavaScript Bugs #2

Open fleq6 opened 2 years ago

fleq6 commented 2 years ago

System Information

Serenade Version: v2.0.1

OS and Version: Windows 11 Version 10.0.22000 Build 22000

Application: VS Code

Issue Description

Bug 1 - Object Methods

When it comes to adding methods to an object, if we use the following shorthand, Serenade will stop working.

const example = {
  name: "Test",
  getName() {
    return this.name;
  }
};

If any object in the document has a method with the previous syntax, Serenade will throw an error with every subsequent command.

Bug 2 - Generator Functions

If there's any generator function present in your code, Serenade will throw an error with every subsequent command.

function* example() {
  yield "Hello World";
}

It doesn't matter where the * is, after the function keyword, before the function name or in the middle.

Bug 3 - Voice Commands to Traverse Arrays

Serenade groups all array elements on a global scale. As it currently stands, it's quite difficult to refactor arrays with Serenade. Let me explain. Example code:

function test() {
  const a = [1, 2];
}

function test2() {
  const b = [3, 4];
  const c = [5, 6, 7];
}

Saying element two takes me to the number 2 in the first array.

Saying element five takes me to the number 5 in the third array.

It doesn't matter where my cursor is, Serenade treats all elements as if they're in the same array. I think the expected behavior is that these commands would prioritize the arrays that are on the same line as the cursor. Or in case of nested arrays it would prioritize the array that the cursor is currently inside of.

Bug 4 - Private Methods & Attributes

In TypeScript, Serenade handles private methods and attributes well. If I'm inside a class and say: add private method hello, I get what you would expect:

class Example {
  private hello() {
  }
}

However, I get the same result in JavaScript, which is wrong. In JavaScript, private methods and attributes are declared with a # sign. So, following the previous example, in JavaScript I should get:

class Example {
  #hello() {
  }
}
tmacwill commented 2 years ago

thanks for the report! agree these are issues worth fixing. (1) and (2) are likely fixed in the tree-sitter grammar, (3) in core, and (4) in corpusgen.

tmacwill commented 2 years ago

(3) should be fixed by #3