Debian Codegraph @

demo/code_lens.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>ACE Code Lens demo</title>
6 <style type="text/css" media="screen">
7 body {
8 overflow: hidden;
9 }
10
11 #editor {
12 margin: 0;
13 position: absolute;
14 top: 0;
15 bottom: 0;
16 left: 0;
17 right: 0;
18 }
19 </style>
20 </head>
21 <body>
22
23 <pre id="editor"></pre>
24
25 <script src="kitchen-sink/require.js"></script>
26 <script>
27 // setup paths
28 require.config({paths: { "ace" : "../src"}});
29 // load ace and extensions
30 require(["ace/ace", "ace/ext/code_lens"], function(ace, codeLens) {
31 var editor = ace.edit("editor");
32 editor.session.setMode("ace/mode/html");
33
34 var commandId = "describeCodeLens";
35 editor.commands.addCommand({
36 name: commandId,
37 exec: function(editor, args) {
38 // services available in `ctx`
39 alert('CodeLens command called with arguments ' + args);
40 }
41 });
42 editor.commands.addCommand({
43 name: "clearCodeLenses",
44 exec: function(editor, args) {
45 editor.setOption("enableCodeLens", false);
46 codeLens.clear(editor.session);
47 }
48 });
49 editor.setOption("enableCodeLens", true);
50
51 codeLens.registerCodeLensProvider(editor, {
52 provideCodeLenses: function(session, callback) {
53 var p = [{
54 start: {row: 0},
55 command: {
56 id: "clearCodeLenses",
57 title: "Clear all code lenses",
58 arguments: []
59 }
60 }];
61 var l = session.getLength()
62
63 for (var row = 2; row < l; row ++) {
64 var line = session.getLine(row);
65 var endColumn = line.length;
66
67 var m = /[{>]\s*$/.exec(line);
68 if (!m) continue;
69
70 p.push({
71 start: {
72 row: row,
73 column: m.index,
74 },
75 command: {
76 id: commandId,
77 title: "Line " + (row + 1),
78 arguments: ["line", row]
79 }
80 });
81
82 if (m.index < 10) continue;
83 p.push({
84 start: {
85 row: row,
86 column: m.index,
87 },
88 end: {
89 row: row,
90 column: m.index + 1,
91 },
92 command: {
93 id: commandId,
94 title: "column " + endColumn,
95 arguments: ["column", endColumn]
96 }
97 });
98
99 if (m.index < 30) continue;
100 p.push({
101 start: {
102 row: row,
103 column: m.index,
104 },
105 command: {
106 id: commandId,
107 title: "Third Link",
108 arguments: ["3", row]
109 }
110 });
111
112 }
113 callback(null, p);
114 }
115 });
116
117 window.editor = editor;
118 window.codeLens = codeLens;
119 });
120 </script>
121
122 <script src="./show_own_source.js"></script>
123 </body>
124 </html>