-
Notifications
You must be signed in to change notification settings - Fork 26
/
lintPanel.js
126 lines (101 loc) · 3.64 KB
/
lintPanel.js
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
125
126
/**
* Interactive Linter Copyright (c) 2015 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (require /*, exports, module*/) {
"use strict";
var EditorManager = brackets.getModule("editor/EditorManager"),
MainViewManager = brackets.getModule("view/MainViewManager"),
WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
Resizer = brackets.getModule("utils/Resizer"),
StringUtils = brackets.getModule("utils/StringUtils"),
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
linterManager = require("linterManager"),
linterReporter = require("linterReporter"),
panelTemplate = require("text!templates/problemsPanel.html"),
resultsTemplate = require("text!templates/problemsPanelTable.html"),
collapsed = true,
hasErrors = false;
var $problemsPanel, $problemsPanelTable;
function handleIndicatorClick() {
if (!hasErrors) {
hidePanel();
}
else {
if (Resizer.isVisible($problemsPanel)) {
collapsed = true;
hidePanel();
}
else {
collapsed = false;
showPanel();
}
}
}
function showPanel() {
if (hasErrors) {
Resizer.show($problemsPanel);
}
}
function hidePanel() {
Resizer.hide($problemsPanel);
}
function createPanel() {
var $panelHtml = $(Mustache.render(panelTemplate));
WorkspaceManager.createBottomPanel("interactive-linter.linting.messages", $panelHtml, 100);
$problemsPanel = $("#interactive-linter-problems-panel");
$problemsPanel.on("click", ".close", function () {
collapsed = true;
hidePanel();
});
$problemsPanelTable = $problemsPanel.find(".table-container");
$problemsPanelTable.on("click", "tr", function () {
var $target = $(this);
var line = $target.data("line"); // Convert from friendly line to actual line number
var ch = $target.data("character");
// if there is no line number available, don't do anything
if (!isNaN(line) && !isNaN(ch)) {
line -= 1;
ch -= 1;
var editor = EditorManager.getCurrentFullEditor();
editor.setCursorPos(line, ch, true);
MainViewManager.focusActivePane();
}
});
}
function updateTitle(numProblems) {
var isPlural = numProblems !== 1;
var message = StringUtils.format("Interactive Linter: {0} Linter Problem{1}", numProblems, isPlural ? "s" : "");
$problemsPanel.find(".title").text(message);
}
function handleMessages(messages) {
if (messages) {
hasErrors = true;
var html = Mustache.render(resultsTemplate, {messages: messages});
$problemsPanelTable
.empty()
.append($(html))
.scrollTop(0);
if (!collapsed) {
showPanel();
}
updateTitle(messages.length);
}
else {
hasErrors = false;
hidePanel();
}
}
$(linterReporter).on("lintMessage", function (evt, messages) {
handleMessages(messages);
});
$(linterManager).on("linterNotFound", function () {
hasErrors = false;
hidePanel();
});
createPanel();
$(document).on("click", "#interactive-linter-lint-indicator", function () {
handleIndicatorClick();
});
});