src/Tools/VSCode/extension/src/completion.ts
author wenzelm
Sat, 10 Jun 2017 21:34:05 +0200
changeset 66060 b2bfbefd354f
child 66072 fd26cf23e9b2
permissions -rw-r--r--
symbol completion that bypasses the LS protocol, and thus observes the range properly; more symbol operations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
66060
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     1
'use strict';
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     2
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     3
import * as symbol from './symbol'
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     4
import { CompletionItemProvider, CompletionItem, TextDocument, Range, Position,
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     5
  CancellationToken, CompletionList } from 'vscode'
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     6
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     7
export class Completion_Provider implements CompletionItemProvider
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     8
{
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
     9
  public provideCompletionItems(
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    10
    document: TextDocument, position: Position, token: CancellationToken): CompletionList
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    11
  {
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    12
    const line_text = document.lineAt(position).text
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    13
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    14
    let i = position.character
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    15
    while (i > 0 && line_text.charAt(i - 1) !== "\\") { i = i - 1 }
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    16
    const start = i - 1
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    17
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    18
    let result = undefined as CompletionList
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    19
    if (start >= 0 && line_text.charAt(start) == "\\") {
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    20
      const s = line_text.substring(start + 1, position.character)
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    21
      if (symbol.is_ascii_identifier(s)) {
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    22
        const items =
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    23
          symbol.complete_name(s).map((sym) =>
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    24
          {
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    25
            return {
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    26
              label: sym,
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    27
              detail: `(symbol ${symbol.get_unicode(sym)})`,
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    28
              range: new Range(new Position(position.line, start), position)
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    29
            }
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    30
          })
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    31
        result = new CompletionList(items)
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    32
      }
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    33
    }
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    34
    return result
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    35
  }
b2bfbefd354f symbol completion that bypasses the LS protocol, and thus observes the range properly;
wenzelm
parents:
diff changeset
    36
}