xi-editor/xi-editor

auto indent followup work

Open

#1003 opened on Nov 21, 2018

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Rust (19,842 stars) (708 forks)batch import
enhancementhelp wantedsyntect-plugin

Description

There are a few pieces of followup to #991 that would be nice to do at some point:

  • Only send a single delta per edit: currently, when adjusting indentation when there are multiple cursors, we will send a delta per cursor, which is less efficient. To correct this, we should create a single DeltaBuilder in the consider_indentation fn, and then pass that into the functions that compute the indentation changes; these functions would add their changes to the shared delta, which would only be sent once at the end of consider_indentation.

  • decrease indent on return, when appropriate. For instance, imagine you are adding newlines to some minified JSON:

    // started with:
    {"abcs":["a","b","c"]}
    
    // current state:
    {
      "abcs": [
        "a",
        "b",
        "c"
        ]}
    

    If your cursor is between the final ] and }, return should decrease the indent of the line with the ] by one level, and the line with } by an additional level. Currently, we do not test for decrease on the 'current' line when a newline is added.

  • ignore comment blocks when calculating indentation status: Currently indentation does not know about comments. This means that if you have a commented line that would otherwise affect indentation (in rust, say, // fn main() {) indentation will be adjusted as if the line were not commented.

    Doing this correctly will likely require moving all of the indentation logic out of the Syntect object and into the PluginState object, and having the logic all run during idle, alongside syntax highlighting; this will let us guarantee that a given line's scope is always in the cache.

Contributor guide