Skip to content
New issue

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

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

Already on GitHub? # to your account

Add textobject for javascript #3213

Merged
merged 7 commits into from
Jul 28, 2022

Conversation

erasin
Copy link
Contributor

@erasin erasin commented Jul 27, 2022

Fix #3177

@the-mikedavis
Copy link
Member

To fix the docs CI, you'll need to run cargo xtask docgen and commit the changes

@axin
Copy link

axin commented Jul 27, 2022

You have forgotten about generator functions and class expressions:

(generator_function_declaration
  body: (_) @function.inside) @function.around

(class
  (class_body) @class.inside) @class.around

@David-Else
Copy link
Contributor

Thanks for this! Can we get all of: https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/master/queries/javascript/textobjects.scm ? (Sorry I don't really know the technical details of this matter)

@the-mikedavis the-mikedavis self-requested a review July 27, 2022 15:03
@the-mikedavis
Copy link
Member

It looks like this already covers the textobjects from nvim-treesitter which are implemented in helix (i.e. not ones like conditional or loop)

@erasin
Copy link
Contributor Author

erasin commented Jul 28, 2022

this is my test file,

  • comment
  • function
  • arguments
  • class
    • interface (ts)
    • type (ts)
// js

// function
function a() { }
function b(b1) { }
export function c() { }
const d = function() { }
const e = {
  f1: function(c, d) { },
  f2: () => { }
}
const f1 = (a) => { }
const f2 = () => { () => { }; }
const f3 = f1(() => { })
const f4 = x => x + 1

// class
class A {
  constructor() { }
  tes1(a, b = 1) { }
}

export class B { }
const C = class { }

// ts 

interface I1 {
  s: string
  b: boolean
  (b: boolean): string
}

type T2 = {
  s: string
  b: boolean
  f: () => void
}

class D implements I1 {

  constructor(s: string, b: boolean) {
    this.s = s
    this.b = b
  }

  s: string
  b: boolean

  f(b: boolean): string {
    return b ? "ok": ""
  }
}

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look great, thanks for working on this!

@the-mikedavis the-mikedavis merged commit 681c0a9 into helix-editor:master Jul 28, 2022
GreasySlug pushed a commit to GreasySlug/helix that referenced this pull request Aug 2, 2022
thomasskk pushed a commit to thomasskk/helix that referenced this pull request Sep 9, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Textobject queries for TS and JS
4 participants