GithubHelp home page GithubHelp logo

Comments (10)

Wansmer avatar Wansmer commented on June 18, 2024 8

I found a case, why error presented:
( code from luajit-remake )

static void NO_RETURN HandleMetatableSlowPath(TValue tvIndex, TValue base, TValue metamethod) {
  while (true) {
    // Calling plugin ':TSJSplit' when cursor at 'likely' { row 9, col 13 }.
    // The 'if_statement' NOT configured with "{ target_nodes = { 'compound_statement' } }". 
    // TreeSJ continue search for suitable node up and found 'compound_statement' at line(row) 2. 
    // 'compound_statement' is already splitted. Repeated split (without "split = { recursive = true }")
    // is joining all nested multiline node to one line.
    if (likely(metamethod.Is<tHeapEntity>())) {
      HeapEntityType mmType = metamethod.GetHeapEntityType();
      if (mmType == HeapEntityType::Function) {
        MakeCall(metamethod.As<tFunction>(), base, tvIndex,
                 GlobalGetMetamethodCallContinuation);
      } else if (mmType == HeapEntityType::Table) {
        assert(tvIndex.Is<tString>());
        HeapPtr<HeapString> index = tvIndex.As<tString>();
        HeapPtr<TableObject> tableObj = metamethod.As<tTable>();
        GetByIdICInfo icInfo;
        TableObject::PrepareGetById(
            tableObj, UserHeapPointer<HeapString>{index}, icInfo /*out*/);
        TValue result = TableObject::GetById(tableObj, index, icInfo);
        if (likely(!icInfo.m_mayHaveMetatable || !result.Is<tNil>())) {
          Return(result);
        }
        EnterSlowPath<CheckMetatableSlowPath>(tableObj);
      }
    }
  }
}

When trying 'split' already split block, sticky-cursor work wrong. I'll think, how correctly handle this. At the moment, I just hide error with safe calling.

from treesj.

ViRu-ThE-ViRuS avatar ViRu-ThE-ViRuS commented on June 18, 2024 1

It cannot detect 'if_statement' outside 'if_statement'. And I don't understand for why it can be need? :-) Here, plugin found a compound_statement of function because it is the closest suitable node. See 'How it works' in readme.

You can strongly restrict split/join 'compound_statement' if it contains 'if_statement':

local cpp = {
  compound_statement = u.set_preset_for_list({
    both = {
      separator = ';',
      last_separator = true,
      no_format_with = { 'if_statement' },
    },
  }),
  if_statement = { target_nodes = { 'compound_statement' } },
}

I see, should have studied the README.md more :'). Thank you!
Although, Ive seen to be a better/more general config:

local cpp = {
  compound_statement = u.set_preset_for_statement({
    both = {
      separator = ';',
      last_separator = true,
      no_format_with = { 'compound_statement' },
    },
  }),
  if_statement = { target_nodes = { 'compound_statement' } },
}

In my plan, implement functionality, when it will be able to configure same node the different depending on the context. Maybe it will solve it task.

YES! this would definitely give more control to the user as well as the plugin itself! I vote its a good feature to add.
Ill go update the overall config ive found to be generally useful for Cpp / Python in PRs!

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024 1

YES! this would definitely give more control to the user as well as the plugin itself! I vote its a good feature to add. Ill go update the overall config ive found to be generally useful for Cpp / Python in PRs!

Excellent! Please, add tests in a PR according to 'tests/README.md'

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024

I can't reproduce this bug. Maybe you're calling plugin when this fragment inside another node and the error happen on it?
Nevertheless, I will look for the error. Thanks for helpings.

cpp.mov

from treesj.

ViRu-ThE-ViRuS avatar ViRu-ThE-ViRuS commented on June 18, 2024

Hey! I cannot reproduce the bug either anymore, it might be I was on an older version of plugin or something. But you have given me a workable idea:

Is it possible to only affect the compound_statements inside an if_statement, not in general?
Because this config (as can be seen in your comment), will change the entire function if im outside an if_statement because it is a compound_statement.

Some nodes can be seen to have names as well in TS Playground, can these names/titles be supported in TreesJ, not just the name of the node?
Eg: In the code sample we are discussing, if_clause has 2 compound_statements inside, one with name consequence and other with alternative. It would be trivial if these names could be used instead of the general compound_statement.

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024

Is it possible to only affect the compound_statements inside an if_statement, not in general?

Not sure what I correctly understood your question, but '{ target_nodes = { ... } }' just for it.

Some nodes can be seen to have names as well in TS Playground, can these names/titles be supported in TreesJ, not just the name of the node?

Hmm, you mean like it configured in javascript for try_statement what contains few statement_block in catch_clause and finaly_clause?

from treesj.

ViRu-ThE-ViRuS avatar ViRu-ThE-ViRuS commented on June 18, 2024

Some nodes can be seen to have names as well in TS Playground, can these names/titles be supported in TreesJ, not just the name of the node?

Hmm, you mean like it configured in javascript for try_statement what contains few statement_block in catch_clause and finaly_clause?

Screen Shot 2022-11-25 at 22 29 28

Like in this setup, can the red highlighted condition and consequence and alternative be added as nodes to the config? EG:

javascript = {

-- is this possible?
    condition = { --[[ ]] },
    consequence = { --[[ ]] },
    alternative = { --[[ ]] },

-- instead of this
    statement_block = { -- [[ ]] },
    parenthesized_expression = { --[[ ]] },
    else_clause = { -- [[ ]] }
}

this way, only say condition node for if_statement will be effect, not any other parenthesized_expression nodes in the program.

Is it possible to only affect the compound_statements inside an if_statement, not in general?

Not sure what I correctly understood your question, but '{ target_nodes = { ... } }' just for it.

this is related to the above as well.
Basically, the problem im facing is:

upload.mov

IE: with the config:

cpp = {
            compound_statement = treesj_utils.set_preset_for_list({
                both = {
                    separator = ';',
                    last_separator = true,
                    no_format_with = {}
                }
            }),
            if_statement = { target_nodes = { 'compound_statement' }}
}

Split/Join work perfectly when on/inside the if_statement.
But Split when outside the if_statement, but still inside the function body (which itself is a compound_statement), will destroy the formatting of the function body, and also place the cursor at a seemingly weird position. Join in this case makes the function body in one line.

I hope to achieve the behavior where, if_statement still works the same as above,
but calling Split/Join has no effect when outside if_statement.

This can be made possible, as I mention in the previous reply:

Screen Shot 2022-11-25 at 22 48 35

If we can just add configs for consequence which is specific, but no need for compound_statement which is general.

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024

It cannot detect 'if_statement' outside 'if_statement'. And I don't understand for why it can be need? :-) Here, plugin found a compound_statement of function because it is the closest suitable node. See 'How it works' in readme.

You can strongly restrict split/join 'compound_statement' if it contains 'if_statement':

local cpp = {
  compound_statement = u.set_preset_for_list({
    both = {
      separator = ';',
      last_separator = true,
      no_format_with = { 'if_statement' },
    },
  }),
  if_statement = { target_nodes = { 'compound_statement' } },
}

In my plan, implement functionality, when it will be able to configure same node the different depending on the context. Maybe it will solve it task.

from treesj.

ViRu-ThE-ViRuS avatar ViRu-ThE-ViRuS commented on June 18, 2024

Keeping issue open till original error is resolved.

from treesj.

Wansmer avatar Wansmer commented on June 18, 2024

Fixed in #18

from treesj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.