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