author | wenzelm |
Mon, 11 Mar 2019 18:58:06 +0100 | |
changeset 69898 | 990c6e8faf2c |
parent 69256 | c78c95d2a3d1 |
child 70302 | 9ea7081c3f03 |
permissions | -rw-r--r-- |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/VSCode/src/vscode_rendering.scala |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
3 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
4 |
Isabelle/VSCode-specific implementation of quasi-abstract rendering and |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
5 |
markup interpretation. |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
6 |
*/ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
7 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.vscode |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
9 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
10 |
|
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
11 |
import isabelle._ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
12 |
|
64778
7884a19de325
proper interpretation of Resources.source_file as platform file;
wenzelm
parents:
64777
diff
changeset
|
13 |
import java.io.{File => JFile} |
7884a19de325
proper interpretation of Resources.source_file as platform file;
wenzelm
parents:
64777
diff
changeset
|
14 |
|
65913 | 15 |
import scala.annotation.tailrec |
16 |
||
64778
7884a19de325
proper interpretation of Resources.source_file as platform file;
wenzelm
parents:
64777
diff
changeset
|
17 |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
18 |
object VSCode_Rendering |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
19 |
{ |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
20 |
/* decorations */ |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
21 |
|
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
22 |
private def color_decorations(prefix: String, types: Set[Rendering.Color.Value], |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
23 |
colors: List[Text.Info[Rendering.Color.Value]]): List[Document_Model.Decoration] = |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
24 |
{ |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
25 |
val color_ranges = |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
26 |
(Map.empty[Rendering.Color.Value, List[Text.Range]] /: colors) { |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
27 |
case (m, Text.Info(range, c)) => m + (c -> (range :: m.getOrElse(c, Nil))) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
28 |
} |
65105 | 29 |
types.toList.map(c => |
65140 | 30 |
Document_Model.Decoration.ranges(prefix + c.toString, color_ranges.getOrElse(c, Nil).reverse)) |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
31 |
} |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
32 |
|
65176 | 33 |
private val background_colors = |
34 |
Rendering.Color.background_colors - Rendering.Color.active - Rendering.Color.active_result - |
|
35 |
Rendering.Color.entity |
|
36 |
||
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
37 |
private val dotted_colors = |
65134
511bf19348d3
clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents:
65122
diff
changeset
|
38 |
Set(Rendering.Color.writeln, Rendering.Color.information, Rendering.Color.warning) |
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
39 |
|
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65095
diff
changeset
|
40 |
|
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
41 |
/* diagnostic messages */ |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
42 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
43 |
private val message_severity = |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
44 |
Map( |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
45 |
Markup.LEGACY -> Protocol.DiagnosticSeverity.Warning, |
65095 | 46 |
Markup.ERROR -> Protocol.DiagnosticSeverity.Error) |
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
47 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
48 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
49 |
/* markup elements */ |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
50 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
51 |
private val diagnostics_elements = |
65134
511bf19348d3
clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents:
65122
diff
changeset
|
52 |
Markup.Elements(Markup.LEGACY, Markup.ERROR) |
65095 | 53 |
|
65176 | 54 |
private val background_elements = |
55 |
Rendering.background_elements - Markup.ENTITY -- Rendering.active_elements |
|
56 |
||
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
57 |
private val dotted_elements = |
65134
511bf19348d3
clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents:
65122
diff
changeset
|
58 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING) |
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
59 |
|
65134
511bf19348d3
clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents:
65122
diff
changeset
|
60 |
val tooltip_elements = |
511bf19348d3
clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents:
65122
diff
changeset
|
61 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.BAD) ++ |
511bf19348d3
clarified messages (with improved scalability): legacy/error as diagnostics, writeln/information/warning/bad as tooltips (dynamic hover);
wenzelm
parents:
65122
diff
changeset
|
62 |
Rendering.tooltip_elements |
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
63 |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
64 |
private val hyperlink_elements = |
64833 | 65 |
Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.POSITION, Markup.CITATION) |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
66 |
} |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
67 |
|
66114 | 68 |
class VSCode_Rendering(snapshot: Document.Snapshot, _model: Document_Model) |
69 |
extends Rendering(snapshot, _model.resources.options, _model.session) |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
70 |
{ |
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
71 |
rendering => |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
72 |
|
66114 | 73 |
def model: Document_Model = _model |
66143 | 74 |
def resources: VSCode_Resources = model.resources |
66114 | 75 |
|
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
76 |
|
66152 | 77 |
/* bibtex */ |
78 |
||
79 |
def bibtex_entries_iterator(): Iterator[Text.Info[(String, Document_Model)]] = |
|
80 |
Bibtex.entries_iterator(resources.get_models) |
|
81 |
||
82 |
def bibtex_completion(history: Completion.History, caret: Text.Offset): Option[Completion.Result] = |
|
83 |
Bibtex.completion(history, rendering, caret, resources.get_models) |
|
84 |
||
85 |
||
64877 | 86 |
/* completion */ |
87 |
||
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
88 |
def completion(caret_pos: Line.Position, caret: Text.Offset): List[Protocol.CompletionItem] = |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
89 |
{ |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
90 |
val doc = model.content.doc |
66057 | 91 |
val line = caret_pos.line |
92 |
doc.offset(Line.Position(line)) match { |
|
93 |
case None => Nil |
|
94 |
case Some(line_start) => |
|
95 |
val history = Completion.History.empty |
|
96 |
val caret_range = before_caret_range(caret) |
|
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
97 |
|
66057 | 98 |
val syntax = model.syntax() |
99 |
val syntax_completion = |
|
67005 | 100 |
syntax.complete(history, unicode = false, explicit = true, |
66057 | 101 |
line_start, doc.lines(line).text, caret - line_start, |
102 |
language_context(caret_range) getOrElse syntax.language_context) |
|
64877 | 103 |
|
66057 | 104 |
val (no_completion, semantic_completion) = |
105 |
rendering.semantic_completion_result( |
|
66114 | 106 |
history, false, syntax_completion.map(_.range), caret_range) |
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
107 |
|
66057 | 108 |
if (no_completion) Nil |
109 |
else { |
|
66121 | 110 |
val results = |
66157 | 111 |
Completion.Result.merge(history, |
66151 | 112 |
semantic_completion, |
113 |
syntax_completion, |
|
66153 | 114 |
VSCode_Spell_Checker.completion(rendering, caret), |
66159 | 115 |
path_completion(caret), |
66153 | 116 |
bibtex_completion(history, caret)) |
66142 | 117 |
val items = |
118 |
results match { |
|
119 |
case None => Nil |
|
120 |
case Some(result) => |
|
121 |
result.items.map(item => |
|
122 |
Protocol.CompletionItem( |
|
123 |
label = item.replacement, |
|
124 |
detail = Some(item.description.mkString(" ")), |
|
125 |
range = Some(doc.range(item.range)))) |
|
126 |
} |
|
127 |
items ::: VSCode_Spell_Checker.menu_items(rendering, caret) |
|
66057 | 128 |
} |
66054
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
129 |
} |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
130 |
} |
fb0eea226a4d
more uniform syntax_completion + semantic_completion;
wenzelm
parents:
65925
diff
changeset
|
131 |
|
64877 | 132 |
|
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
133 |
/* diagnostics */ |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
134 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
135 |
def diagnostics: List[Text.Info[Command.Results]] = |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
136 |
snapshot.cumulate[Command.Results]( |
67824
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
137 |
model.content.text_range, Command.Results.empty, VSCode_Rendering.diagnostics_elements, |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
138 |
command_states => |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
139 |
{ |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
140 |
case (res, Text.Info(_, msg @ XML.Elem(Markup(Markup.BAD, Markup.Serial(i)), body))) |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
141 |
if body.nonEmpty => Some(res + (i -> msg)) |
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
142 |
|
67824
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
143 |
case (res, Text.Info(_, msg)) => |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
144 |
Command.State.get_result_proper(command_states, msg.markup.properties).map(res + _) |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
145 |
|
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
146 |
case _ => None |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67005
diff
changeset
|
147 |
}).filterNot(info => info.info.is_empty) |
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
148 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
149 |
def diagnostics_output(results: List[Text.Info[Command.Results]]): List[Protocol.Diagnostic] = |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
150 |
{ |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
151 |
(for { |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
152 |
Text.Info(text_range, res) <- results.iterator |
64830 | 153 |
range = model.content.doc.range(text_range) |
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
154 |
(_, XML.Elem(Markup(name, _), body)) <- res.iterator |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
155 |
} yield { |
66143 | 156 |
val message = resources.output_pretty_message(body) |
64679
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
157 |
val severity = VSCode_Rendering.message_severity.get(name) |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
158 |
Protocol.Diagnostic(range, message, severity = severity) |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
159 |
}).toList |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
160 |
} |
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
161 |
|
b2bf280b7e13
more uniform treatment of input/output wrt. client;
wenzelm
parents:
64668
diff
changeset
|
162 |
|
65146 | 163 |
/* text color */ |
164 |
||
165 |
def text_color(range: Text.Range): List[Text.Info[Rendering.Color.Value]] = |
|
166 |
{ |
|
167 |
snapshot.select(range, Rendering.text_color_elements, _ => |
|
168 |
{ |
|
65174
c0388fbd8096
avoid extra decorations for regular command keywords;
wenzelm
parents:
65173
diff
changeset
|
169 |
case Text.Info(_, XML.Elem(Markup(name, props), _)) => |
c0388fbd8096
avoid extra decorations for regular command keywords;
wenzelm
parents:
65173
diff
changeset
|
170 |
if (name != Markup.IMPROPER && props.contains((Markup.KIND, Markup.COMMAND))) None |
c0388fbd8096
avoid extra decorations for regular command keywords;
wenzelm
parents:
65173
diff
changeset
|
171 |
else Rendering.text_color.get(name) |
65146 | 172 |
}) |
173 |
} |
|
174 |
||
175 |
||
65913 | 176 |
/* text overview color */ |
177 |
||
178 |
private sealed case class Color_Info( |
|
179 |
color: Rendering.Color.Value, offset: Text.Offset, end_offset: Text.Offset, end_line: Int) |
|
180 |
||
181 |
def text_overview_color: List[Text.Info[Rendering.Color.Value]] = |
|
182 |
{ |
|
183 |
@tailrec def loop(offset: Text.Offset, line: Int, lines: List[Line], colors: List[Color_Info]) |
|
184 |
: List[Text.Info[Rendering.Color.Value]] = |
|
185 |
{ |
|
186 |
if (lines.nonEmpty) { |
|
187 |
val end_offset = offset + lines.head.text.length |
|
188 |
val colors1 = |
|
189 |
(overview_color(Text.Range(offset, end_offset)), colors) match { |
|
190 |
case (Some(color), old :: rest) if color == old.color && line == old.end_line => |
|
191 |
old.copy(end_offset = end_offset, end_line = line + 1) :: rest |
|
192 |
case (Some(color), _) => |
|
193 |
Color_Info(color, offset, end_offset, line + 1) :: colors |
|
194 |
case (None, _) => colors |
|
195 |
} |
|
196 |
loop(end_offset + 1, line + 1, lines.tail, colors1) |
|
197 |
} |
|
198 |
else { |
|
199 |
colors.reverse.map(info => |
|
200 |
Text.Info(Text.Range(info.offset, info.end_offset), info.color)) |
|
201 |
} |
|
202 |
} |
|
203 |
loop(0, 0, model.content.doc.lines, Nil) |
|
204 |
} |
|
205 |
||
206 |
||
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
207 |
/* dotted underline */ |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
208 |
|
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
209 |
def dotted(range: Text.Range): List[Text.Info[Rendering.Color.Value]] = |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
210 |
message_underline_color(VSCode_Rendering.dotted_elements, range) |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
211 |
|
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65120
diff
changeset
|
212 |
|
65095 | 213 |
/* decorations */ |
214 |
||
65120
db6cc23fcf33
proper reset of published decorations: initial value is Nil, afterwards it is a list of canonical length and order;
wenzelm
parents:
65107
diff
changeset
|
215 |
def decorations: List[Document_Model.Decoration] = // list of canonical length and order |
65925 | 216 |
Par_List.map((f: () => List[Document_Model.Decoration]) => f(), |
217 |
List( |
|
218 |
() => |
|
219 |
VSCode_Rendering.color_decorations("background_", VSCode_Rendering.background_colors, |
|
220 |
background(VSCode_Rendering.background_elements, model.content.text_range, Set.empty)), |
|
221 |
() => |
|
222 |
VSCode_Rendering.color_decorations("foreground_", Rendering.Color.foreground_colors, |
|
223 |
foreground(model.content.text_range)), |
|
224 |
() => |
|
225 |
VSCode_Rendering.color_decorations("text_", Rendering.Color.text_colors, |
|
226 |
text_color(model.content.text_range)), |
|
227 |
() => |
|
228 |
VSCode_Rendering.color_decorations("text_overview_", Rendering.Color.text_overview_colors, |
|
229 |
text_overview_color), |
|
230 |
() => |
|
231 |
VSCode_Rendering.color_decorations("dotted_", VSCode_Rendering.dotted_colors, |
|
232 |
dotted(model.content.text_range)))).flatten ::: |
|
66141 | 233 |
List(VSCode_Spell_Checker.decoration(rendering)) |
65095 | 234 |
|
235 |
def decoration_output(decoration: Document_Model.Decoration): Protocol.Decoration = |
|
236 |
{ |
|
237 |
val content = |
|
65105 | 238 |
for (Text.Info(text_range, msgs) <- decoration.content) |
65095 | 239 |
yield { |
240 |
val range = model.content.doc.range(text_range) |
|
65173 | 241 |
Protocol.DecorationOpts(range, |
66143 | 242 |
msgs.map(msg => Protocol.MarkedString(resources.output_pretty_tooltip(msg)))) |
65095 | 243 |
} |
244 |
Protocol.Decoration(decoration.typ, content) |
|
245 |
} |
|
246 |
||
247 |
||
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
248 |
/* tooltips */ |
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
249 |
|
69898 | 250 |
override def timing_threshold: Double = options.real("vscode_timing_threshold") |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
251 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
252 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
253 |
/* hyperlinks */ |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
254 |
|
64667 | 255 |
def hyperlink_source_file(source_name: String, line1: Int, range: Symbol.Range) |
256 |
: Option[Line.Node_Range] = |
|
257 |
{ |
|
64775 | 258 |
for { |
66143 | 259 |
platform_path <- resources.source_file(source_name) |
64778
7884a19de325
proper interpretation of Resources.source_file as platform file;
wenzelm
parents:
64777
diff
changeset
|
260 |
file <- |
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66234
diff
changeset
|
261 |
(try { Some(File.absolute(new JFile(platform_path))) } |
64778
7884a19de325
proper interpretation of Resources.source_file as platform file;
wenzelm
parents:
64777
diff
changeset
|
262 |
catch { case ERROR(_) => None }) |
64775 | 263 |
} |
64667 | 264 |
yield { |
64778
7884a19de325
proper interpretation of Resources.source_file as platform file;
wenzelm
parents:
64777
diff
changeset
|
265 |
Line.Node_Range(file.getPath, |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
266 |
if (range.start > 0) { |
69256
c78c95d2a3d1
more uniform read_file_content for Isabelle/jEdit and Isabelle/VSCode: make_theory_content is required for semantic checking of user file-formats (e.g. bibtex);
wenzelm
parents:
67824
diff
changeset
|
267 |
resources.get_file_content(resources.node_name(file)) match { |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
268 |
case Some(text) => |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
269 |
val chunk = Symbol.Text_Chunk(text) |
65196
e8760a98db78
discontinued pointless Text.Length: Javascript and Java agree in old-fashioned UTF-16;
wenzelm
parents:
65176
diff
changeset
|
270 |
val doc = Line.Document(text) |
64841
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
271 |
doc.range(chunk.decode(range)) |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
272 |
case _ => |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
273 |
Line.Range(Line.Position((line1 - 1) max 0)) |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
274 |
} |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
275 |
} |
d53696aed874
added node_name(String): imitate jEdit buffer operations;
wenzelm
parents:
64833
diff
changeset
|
276 |
else Line.Range(Line.Position((line1 - 1) max 0))) |
64667 | 277 |
} |
278 |
} |
|
279 |
||
280 |
def hyperlink_command(id: Document_ID.Generic, range: Symbol.Range): Option[Line.Node_Range] = |
|
281 |
{ |
|
282 |
if (snapshot.is_outdated) None |
|
283 |
else |
|
284 |
for { |
|
285 |
start <- snapshot.find_command_position(id, range.start) |
|
286 |
stop <- snapshot.find_command_position(id, range.stop) |
|
287 |
} yield Line.Node_Range(start.name, Line.Range(start.pos, stop.pos)) |
|
288 |
} |
|
289 |
||
290 |
def hyperlink_position(pos: Position.T): Option[Line.Node_Range] = |
|
291 |
pos match { |
|
292 |
case Position.Item_File(name, line, range) => hyperlink_source_file(name, line, range) |
|
293 |
case Position.Item_Id(id, range) => hyperlink_command(id, range) |
|
294 |
case _ => None |
|
295 |
} |
|
296 |
||
297 |
def hyperlink_def_position(pos: Position.T): Option[Line.Node_Range] = |
|
298 |
pos match { |
|
299 |
case Position.Item_Def_File(name, line, range) => hyperlink_source_file(name, line, range) |
|
300 |
case Position.Item_Def_Id(id, range) => hyperlink_command(id, range) |
|
301 |
case _ => None |
|
302 |
} |
|
303 |
||
64651 | 304 |
def hyperlinks(range: Text.Range): List[Line.Node_Range] = |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
305 |
{ |
64651 | 306 |
snapshot.cumulate[List[Line.Node_Range]]( |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
307 |
range, Nil, VSCode_Rendering.hyperlink_elements, _ => |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
308 |
{ |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
309 |
case (links, Text.Info(_, XML.Elem(Markup.Path(name), _))) => |
65488 | 310 |
val file = perhaps_append_file(snapshot.node_name, name) |
64654 | 311 |
Some(Line.Node_Range(file) :: links) |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
312 |
|
64667 | 313 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
314 |
hyperlink_def_position(props).map(_ :: links) |
|
315 |
||
316 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) => |
|
317 |
hyperlink_position(props).map(_ :: links) |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
318 |
|
64833 | 319 |
case (links, Text.Info(info_range, XML.Elem(Markup.Citation(name), _))) => |
320 |
val iterator = |
|
321 |
for { |
|
66152 | 322 |
Text.Info(entry_range, (entry, model)) <- bibtex_entries_iterator() |
64833 | 323 |
if entry == name |
324 |
} yield Line.Node_Range(model.node_name.node, model.content.doc.range(entry_range)) |
|
325 |
if (iterator.isEmpty) None else Some((links /: iterator)(_ :+ _)) |
|
326 |
||
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
327 |
case _ => None |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
328 |
}) match { case Text.Info(_, links) :: _ => links.reverse case _ => Nil } |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64622
diff
changeset
|
329 |
} |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
diff
changeset
|
330 |
} |