title: How to implement complicated auto-indentation in VScode
body: <p>I am working on a language extension for SAS for VScode. I previously worked on the SAS language extension for Atom (<a href="https://github.com/akanosora/language-sas" rel="nofollow noreferrer">https://github.com/akanosora/language-sas</a>) as well as Vim (part of the default Vim packages: <a href="https://github.com/vim/vim/blob/master/runtime/indent/sas.vim" rel="nofollow noreferrer">https://github.com/vim/vim/blob/master/runtime/indent/sas.vim</a>).</p>
  
  <p>I am not very satisfied with the auto-indentation implementation in Atom and it seems that VScode provides more or less the same mechanism for auto-indentation.</p>
  
  <p>The proper indentation for SAS code is quite tricky as the closing of a block is not always mandatory. A block in SAS typically starts with <code>data</code> or <code>proc</code> and ends with <code>run</code> or <code>quit</code>, and you can skip <code>run</code> to close it. For example, the following codes are both okay in SAS:</p>
  
  <pre><code>data female; 
      set total;
      where gender = 0;
  run;
  
  data male; 
      set total;
      where gender = 1;
  run; 
  </code></pre>
  
  <p>or</p>
  
  <pre><code>data female; 
      set total;
      where gender = 0;
  
  data male; 
      set total;
      where gender = 1;
  run; 
  </code></pre>
  
  <p>So a proper auto-indentation for SAS requires more complicated rules than <code>increaseIndentPattern</code> and <code>decreaseIndentPattern</code> as they do not always pair with each other. I was able to implement that in Vim by comparing the closest <code>run</code> and <code>data</code> above the current line. If the <code>run</code> is more close to the current <code>data</code> line than the previous <code>data</code> line, then no indent is needed. Otherwise, indent the current <code>data</code> line. I want to know how feasible it is to implement that in VScode (maybe not relying on the <code>indentationRules</code> setting but use <code>vscode.languages.*</code> API?) I need some directions.</p>