shinyypig / matlab-in-vscode

A vscode extension for matlab.
MIT License
45 stars 4 forks source link

当查看见变量时,其中有些值是矩阵形式,是否有方法可以继续查看矩阵内详细的值 #37

Closed lyy010714 closed 3 months ago

shinyypig commented 5 months ago

不好意思,实现起来会比较复杂,短期内可能没有时间和精力实现。

cat-my-earn commented 3 months ago

我实现了这个,但是使用openvar命令实现的。

在拓展生成的js文件中修改这两个函数,就可以做到点击变量名然后打开变量了。 第一个函数:生成html的函数。第一个函数里面我还加了一点css,如果不需要的话可以去掉

    async function a(e, t) {
      return o.existsSync(e)
        ? await (function (e) {
            return new Promise((t, s) => {
              let i = `
        <style>
        table {
            font-size: 14px;
            width: 100%;
            table-layout: fixed;
            border-collapse: collapse;
            margin: 10px;
        }
        td, th {
            border: 1px solid gray;
            padding: 5px;
            text-align: left;
        }
        td:active {
            background-color: red;
        }
        </style>
        <table>
        <script>
        const vscode = acquireVsCodeApi();
        function handleClick(e) {
          vscode.postMessage({command: "openvar", text: e.innerText});
        }
        </script>
        `;
              o.createReadStream(e)
                .pipe(r())
                .on("headers", (e) => {
                  i += "<tr>";
                  e.forEach((e) => {
                    i += `<th>${e}</th>`;
                  });
                  i += "</tr>";
                })
                .on("data", (e) => {
                  i += "<tr>";
                  for (let t in e)
                    i += `<td onclick='handleClick(this)'>${e[t]}</td>`;
                  i += "</tr>";
                })
                .on("end", () => {
                  i += "</table>";
                  o.unlink(e, (e) => {
                    e ? s(e) : t(i);
                  });
                })
                .on("error", (e) => {
                  s(e);
                });
            });
          })(e)
        : (await new Promise((e) => setTimeout(e, t)), await a(e, t));
    }

第二个函数:创建webview的函数

        C = t.commands.registerCommand("matlab-in-vscode.variable", () => {
          !(function () {
            let e = h();
            if (e !== undefined) {
              if (!s) {
                s = t.window.createWebviewPanel(
                  "matlabScope",
                  "Matlab Variable Scope",
                  t.ViewColumn.Beside,
                  { enableScripts: true }
                );
                s.onDidDispose(() => {
                  s = undefined;
                });

                // 添加 onDidReceiveMessage 事件监听器
                s.webview.onDidReceiveMessage((message) => {
                  if (message.command === "openvar") {
                    let command = `openvar("${message.text}")`;
                    e.sendText(command);
                  }
                });
              } else {
                s.reveal();
              }
              e.sendText("variable_info;");
              f();
            } else {
              e = m();
            }
          })();
        });
shinyypig commented 3 months ago

已实现。