File: plugin.js

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (68 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download
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
// The jupyterlab extension
// Copyright (C) 2023 Red Hat Inc.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
// Based on: https://github.dev/WardBrian/jupyterlab-stan-highlight
import './stap'
import { INotebookTracker } from '@jupyterlab/notebook';
import { CodeCell } from '@jupyterlab/cells';

function registerStapFileType(app) {
  app.docRegistry.addFileType({
    name: 'systemtap',
    displayName: 'Systemtap',
    extensions: ['stp'],
    mimeTypes: ['text/x-systemtap'],
  });
}

function highlightStapCell(cell) {
  if (cell && cell instanceof CodeCell) {
    let editor = cell.editor;
    let magic = editor.getLine(0)
    if (magic?.trim().startsWith("%%python")) {
      editor.setOption("mode", "text/x-python");
    }else{
      editor.setOption("mode", "text/x-systemtap");
    }
    // For options https://codemirror.net/5/doc/manual.html#Configuration
      editor.setOption("indentUnit", 2);
      editor.setOption('firstLineNumber', 0);
      editor.setOption('lineNumbers', true);
      editor.setOption('smartIndent', true);    
  }
}

export default [{
  id: 'jupyterlab-stap-highlight',
  autoStart: true,
  requires: [INotebookTracker],
  activate: function (app, tracker) {
    console.log('JupyterLab extension jupyterlab-stap-highlight is activated');
    registerStapFileType(app);

    tracker.currentChanged.connect((tr, nbPanel) => {
      nbPanel.revealed.then((r) => {
        nbPanel.content.widgets.forEach((cell, index, array) => {
          highlightStapCell(cell);
        });
      });
    });

    tracker.activeCellChanged.connect(() => {
      highlightStapCell(tracker.activeCell)
    });

    // highlight initally
    tracker.widgetAdded.connect((tr, nbPanel) => {
      nbPanel.revealed.then((r) => {
        nbPanel.content.widgets.forEach((cell, index, array) => {
          highlightStapCell(cell);
        });
      });
    });
  }
}];