@@ -108,7 +108,7 @@ blobsProfiler.viewPropertiesPopup = function(title, data, width, height)
108108 return propertiesFrame
109109end
110110
111- blobsProfiler .generateAceEditorPanel = function (parentPanel , content , editorMode , readOnly , startLine )
111+ blobsProfiler .generateAceEditorPanel = function (parentPanel , content , editorMode , readOnly , startLine , highlightLine )
112112 local dhtmlPanel = vgui .Create (" DHTML" , parentPanel )
113113 content = content or [[ print("Hello world!")]]
114114 editorMode = editorMode or " Lua"
@@ -120,6 +120,28 @@ blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode
120120 useModeFile = " mode-sql"
121121 end
122122
123+ local highlightJS = " "
124+ if highlightLine and highlightLine ~= 0 then
125+ highlightJS = [[
126+ var lineNumber = ]] .. highlightLine - 1 .. [[ ;
127+
128+ var Range = ace.require("ace/range").Range;
129+ editor.session.addMarker(new Range(lineNumber, 0, lineNumber, 1), "errorHighlight", "fullLine");
130+
131+ editor.session.setAnnotations([{
132+ row: lineNumber,
133+ column: 0,
134+ //text: "Error: ", // TODO: Pass through error message?
135+ type: "error"
136+ }]);
137+
138+ setTimeout(function() {
139+ editor.scrollToLine(lineNumber, true, true, function() {});
140+ editor.gotoLine(lineNumber);
141+ }, 100); // murder me in my sleep
142+ ]]
143+ end
144+
123145 dhtmlPanel :SetHTML ([[
124146 <!DOCTYPE html>
125147 <html lang="en">
@@ -128,8 +150,13 @@ blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode
128150 <title>blobsProfiler: Lua Execution</title>
129151 <style type="text/css" media="screen">
130152 #editor {
131- height: 400px;
132- width: 100%;
153+ height: 400px;
154+ width: 100%;
155+ }
156+ .errorHighlight {
157+ position: absolute;
158+ background-color: rgba(255, 0, 0, 0.3);
159+ z-index: 20;
133160 }
134161 </style>
135162 </head>
@@ -159,6 +186,8 @@ blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode
159186 },
160187 readOnly: true // Disable this command in read-only mode
161188 });
189+
190+ ]] .. highlightJS .. [[
162191 </script>
163192 </body>
164193 </html>
169198
170199blobsProfiler .sourceFrames = {}
171200
172- local function popupSourceView (sourceContent , frameTitle )
201+ local function popupSourceView (sourceContent , frameTitle , highlightLine )
202+ print (" highlightLine" , highlightLine )
173203 local sourceFrame = vgui .Create (" DFrame" )
174204 sourceFrame :SetSize (500 ,500 )
175205 sourceFrame :SetTitle (frameTitle or " View source" )
@@ -180,7 +210,7 @@ local function popupSourceView(sourceContent, frameTitle)
180210 startLine = tonumber (startLine )
181211 endLine = tonumber (endLine )
182212
183- local sourcePanel = blobsProfiler .generateAceEditorPanel (sourceFrame , sourceContent , " Lua" , true , startLine )
213+ local sourcePanel = blobsProfiler .generateAceEditorPanel (sourceFrame , sourceContent , " Lua" , true , startLine , highlightLine )
184214 sourcePanel :Dock (FILL )
185215
186216 sourcePanel .OnRemove = function ()
@@ -207,6 +237,7 @@ net.Receive("blobsProfiler:sendSourceChunk", function()
207237 local requestId = net .ReadString ()
208238 local startPos = net .ReadUInt (32 )
209239 local chunk = net .ReadString ()
240+ local highlightLine = net .ReadUInt (16 )
210241
211242 if not receivedSource [requestId ] then
212243 receivedSource [requestId ] = {
@@ -234,7 +265,7 @@ net.Receive("blobsProfiler:sendSourceChunk", function()
234265
235266 if allChunksReceived then
236267 -- local splitRequest = string.Explode(":", requestId)
237- popupSourceView (combinedSource , requestId )
268+ popupSourceView (combinedSource , requestId , highlightLine )
238269
239270 receivedSource [requestId ] = nil -- Clean up the request data
240271 end
@@ -396,6 +427,24 @@ blobsProfiler.Menu.RCFunctions_DEFAULT = {
396427 end ,
397428 icon = " icon16/magnifier.png"
398429 }
430+ },
431+ [" file" ] = {
432+ {
433+ name = " View source" ,
434+ func = function (ref , node , luaState )
435+ if not string .EndsWith (ref .value .Source , " .lua" ) then
436+ Derma_Message (" Invalid file source: " .. ref .value .Source .. " \n Only Lua files can be read!" , " Function view source" , " OK" )
437+ return
438+ end
439+
440+ net .Start (" blobsProfiler:requestSource" )
441+ net .WriteString (ref .value .Source )
442+ net .WriteUInt (ref .value .Line , 16 )
443+ net .WriteUInt (0 , 16 )
444+ net .SendToServer ()
445+ end ,
446+ icon = " icon16/magnifier.png"
447+ }
399448 }
400449}
401450
@@ -1215,6 +1264,10 @@ concommand.Add("blobsprofiler", function(ply, cmd, args, argStr)
12151264 if getSheet .OnActiveTabChanged then
12161265 getSheet :OnActiveTabChanged (nil , getSheet :GetActiveTab ())
12171266 end
1267+
1268+ if moduleTable .OnOpen then
1269+ moduleTable .OnOpen (" Client" , moduleTable .ClientTab )
1270+ end
12181271 end
12191272
12201273 tabServer .OnActiveTabChanged = function (s , pnlOld , pnlNew )
0 commit comments