src/Tools/VSCode/extension/src/decorations.ts
author wenzelm
Tue, 02 Jan 2018 15:38:22 +0100
changeset 67322 734a4e44b159
parent 66097 ee4c2d5b650e
child 68871 f5c76072db55
permissions -rw-r--r--
clarified terminology of "markdown_bullet";
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
     1
'use strict';
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
     2
65973
wenzelm
parents: 65969
diff changeset
     3
import * as timers from 'timers'
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
     4
import { window, OverviewRulerLane } from 'vscode'
65173
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
     5
import { Position, Range, MarkedString, DecorationOptions, DecorationRenderOptions,
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
     6
  TextDocument, TextEditor, TextEditorDecorationType, ExtensionContext, Uri } from 'vscode'
65201
2d01b30e6ac6 clarified modules;
wenzelm
parents: 65182
diff changeset
     7
import { Decoration } from './protocol'
65968
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
     8
import * as library from './library'
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
     9
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    10
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    11
/* known decoration types */
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    12
65104
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    13
const background_colors = [
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    14
  "unprocessed1",
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    15
  "running1",
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    16
  "bad",
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    17
  "intensify",
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    18
  "quoted",
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    19
  "antiquoted",
67322
734a4e44b159 clarified terminology of "markdown_bullet";
wenzelm
parents: 66097
diff changeset
    20
  "markdown_bullet1",
734a4e44b159 clarified terminology of "markdown_bullet";
wenzelm
parents: 66097
diff changeset
    21
  "markdown_bullet2",
734a4e44b159 clarified terminology of "markdown_bullet";
wenzelm
parents: 66097
diff changeset
    22
  "markdown_bullet3",
734a4e44b159 clarified terminology of "markdown_bullet";
wenzelm
parents: 66097
diff changeset
    23
  "markdown_bullet4"
65104
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    24
]
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    25
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    26
const foreground_colors = [
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    27
  "quoted",
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    28
  "antiquoted"
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    29
]
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    30
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    31
const dotted_colors = [
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    32
  "writeln",
65134
511bf19348d3 clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents: 65122
diff changeset
    33
  "information",
511bf19348d3 clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents: 65122
diff changeset
    34
  "warning"
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    35
]
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    36
65146
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    37
const text_colors = [
65181
b4105202751c tuned colors according to Light+ and Dark+ themes;
wenzelm
parents: 65180
diff changeset
    38
  "main",
65146
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    39
  "keyword1",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    40
  "keyword2",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    41
  "keyword3",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    42
  "quasi_keyword",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    43
  "improper",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    44
  "operator",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    45
  "tfree",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    46
  "tvar",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    47
  "free",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    48
  "skolem",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    49
  "bound",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    50
  "var",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    51
  "inner_numeral",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    52
  "inner_quoted",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    53
  "inner_cartouche",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    54
  "inner_comment",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    55
  "dynamic",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    56
  "class_parameter",
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    57
  "antiquote"
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    58
]
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    59
65913
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    60
const text_overview_colors = [
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    61
  "unprocessed",
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    62
  "running",
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    63
  "error",
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    64
  "warning"
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    65
]
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    66
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
    67
66097
ee4c2d5b650e tuned signature;
wenzelm
parents: 65974
diff changeset
    68
/* setup */
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
    69
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
    70
const types = new Map<string, TextEditorDecorationType>()
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
    71
66097
ee4c2d5b650e tuned signature;
wenzelm
parents: 65974
diff changeset
    72
export function setup(context: ExtensionContext)
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    73
{
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    74
  function decoration(options: DecorationRenderOptions): TextEditorDecorationType
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    75
  {
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
    76
    const typ = window.createTextEditorDecorationType(options)
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    77
    context.subscriptions.push(typ)
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    78
    return typ
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    79
  }
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
    80
65104
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    81
  function background(color: string): TextEditorDecorationType
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
    82
  {
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    83
    return decoration(
65968
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
    84
      { light: { backgroundColor: library.get_color(color, true) },
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
    85
        dark: { backgroundColor: library.get_color(color, false) } })
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    86
  }
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
    87
65146
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    88
  function text_color(color: string): TextEditorDecorationType
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    89
  {
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    90
    return decoration(
65968
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
    91
      { light: { color: library.get_color(color, true) },
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
    92
        dark: { color: library.get_color(color, false) } })
65146
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    93
  }
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
    94
65913
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    95
  function text_overview_color(color: string): TextEditorDecorationType
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    96
  {
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
    97
    return decoration(
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
    98
      { overviewRulerLane: OverviewRulerLane.Right,
65968
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
    99
        light: { overviewRulerColor: library.get_color(color, true) },
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
   100
        dark: { overviewRulerColor: library.get_color(color, false) } })
65913
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
   101
  }
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
   102
65142
368004bed323 decorations for spell-checker;
wenzelm
parents: 65135
diff changeset
   103
  function bottom_border(width: string, style: string, color: string): TextEditorDecorationType
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
   104
  {
65142
368004bed323 decorations for spell-checker;
wenzelm
parents: 65135
diff changeset
   105
    const border = `${width} none; border-bottom-style: ${style}; border-color: `
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
   106
    return decoration(
65968
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
   107
      { light: { border: border + library.get_color(color, true) },
44e703278dfd clarified modules;
wenzelm
parents: 65913
diff changeset
   108
        dark: { border: border + library.get_color(color, false) } })
65104
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
   109
  }
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
   110
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   111
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   112
  /* reset */
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   113
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   114
  types.forEach(typ =>
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   115
  {
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
   116
    for (const editor of window.visibleTextEditors) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   117
      editor.setDecorations(typ, [])
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   118
    }
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   119
    const i = context.subscriptions.indexOf(typ)
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   120
    if (i >= 0) context.subscriptions.splice(i, 1)
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   121
    typ.dispose()
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   122
  })
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   123
  types.clear()
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   124
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   125
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   126
  /* init */
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   127
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65153
diff changeset
   128
  for (const color of background_colors) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   129
    types.set("background_" + color, background(color))
65104
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
   130
  }
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65153
diff changeset
   131
  for (const color of foreground_colors) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   132
    types.set("foreground_" + color, background(color)) // approximation
65104
66b19d05dcee decorations for background and foreground colors;
wenzelm
parents: 65098
diff changeset
   133
  }
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65153
diff changeset
   134
  for (const color of dotted_colors) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   135
    types.set("dotted_" + color, bottom_border("2px", "dotted", color))
65122
1edb570f5b17 decorations for dotted underline: less intrusive;
wenzelm
parents: 65106
diff changeset
   136
  }
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65153
diff changeset
   137
  for (const color of text_colors) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   138
    types.set("text_" + color, text_color(color))
65146
69ea3f1715be decorations for text color;
wenzelm
parents: 65142
diff changeset
   139
  }
65913
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
   140
  for (const color of text_overview_colors) {
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
   141
    types.set("text_overview_" + color, text_overview_color(color))
f330f538dae6 support text overview colors via decorations;
wenzelm
parents: 65233
diff changeset
   142
  }
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   143
  types.set("spell_checker", bottom_border("1px", "solid", "spell_checker"))
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   144
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   145
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   146
  /* update editors */
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   147
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
   148
  for (const editor of window.visibleTextEditors) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   149
    update_editor(editor)
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   150
  }
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   151
}
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   152
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   153
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   154
/* decoration for document node */
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   155
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   156
type Content = Range[] | DecorationOptions[]
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   157
const document_decorations = new Map<string, Map<string, Content>>()
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   158
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   159
export function close_document(document: TextDocument)
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   160
{
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   161
  document_decorations.delete(document.uri.toString())
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   162
}
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   163
65173
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   164
export function apply_decoration(decoration: Decoration)
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   165
{
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   166
  const typ = types.get(decoration.type)
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   167
  if (typ) {
65173
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   168
    const uri = Uri.parse(decoration.uri).toString()
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   169
    const content: DecorationOptions[] = decoration.content.map(opt =>
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   170
      {
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   171
        const r = opt.range
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   172
        return {
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   173
          range: new Range(new Position(r[0], r[1]), new Position(r[2], r[3])),
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   174
          hoverMessage: opt.hover_message
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   175
        }
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   176
      })
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   177
65173
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   178
    const document = document_decorations.get(uri) || new Map<string, Content>()
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   179
    document.set(decoration.type, content)
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   180
    document_decorations.set(uri, document)
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   181
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
   182
    for (const editor of window.visibleTextEditors) {
65173
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   183
      if (uri === editor.document.uri.toString()) {
3700be571a01 more compact protocol message;
wenzelm
parents: 65171
diff changeset
   184
        editor.setDecorations(typ, content)
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   185
      }
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   186
    }
65094
386d9d487f62 support for decorations;
wenzelm
parents:
diff changeset
   187
  }
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   188
}
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   189
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   190
export function update_editor(editor: TextEditor)
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   191
{
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   192
  if (editor) {
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65153
diff changeset
   193
    const decorations = document_decorations.get(editor.document.uri.toString())
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   194
    if (decorations) {
65168
9eabc312a2a2 prefer immutable bindings;
wenzelm
parents: 65153
diff changeset
   195
      for (const [typ, content] of decorations) {
65182
973b7669e7d9 proper Map operations;
wenzelm
parents: 65181
diff changeset
   196
        editor.setDecorations(types.get(typ), content)
65135
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   197
      }
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   198
    }
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   199
  }
158cba86140f maintain decorations for document (model) and update it for each editor (view);
wenzelm
parents: 65134
diff changeset
   200
}
65233
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   201
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   202
65973
wenzelm
parents: 65969
diff changeset
   203
/* handle document changes */
65233
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   204
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   205
const touched_documents = new Set<TextDocument>()
65974
fd5f80ee2de0 clarified event handling;
wenzelm
parents: 65973
diff changeset
   206
let touched_timer: NodeJS.Timer
65233
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   207
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   208
function update_touched_documents()
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   209
{
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   210
  const touched_editors: TextEditor[] = []
65969
1f93eb5c3d77 tuned imports;
wenzelm
parents: 65968
diff changeset
   211
  for (const editor of window.visibleTextEditors) {
65233
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   212
    if (touched_documents.has(editor.document)) {
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   213
      touched_editors.push(editor)
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   214
    }
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   215
  }
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   216
  touched_documents.clear
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   217
  touched_editors.forEach(update_editor)
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   218
}
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   219
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   220
export function touch_document(document: TextDocument)
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   221
{
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   222
  if (touched_timer) timers.clearTimeout(touched_timer)
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   223
  touched_documents.add(document)
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   224
  touched_timer = timers.setTimeout(update_touched_documents, 1000)
e37209c0a42a always update decorations eventually after document changes: VSCode might reset it, but PIDE might produce an unchanged result that is not published again;
wenzelm
parents: 65201
diff changeset
   225
}