From 9874c9e0ede48c866ba9c1d7c36c0d5745089fa4 Mon Sep 17 00:00:00 2001 From: astrochemx <105541001+astrochemx@users.noreply.github.com> Date: Wed, 17 Jul 2024 20:15:50 +0300 Subject: [PATCH 1/6] Add proper `problemMatcher` to the `npm watch` task --- .vscode/extensions.json | 13 +++++++------ .vscode/tasks.json | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 1261c5ddb..8099e8562 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,9 @@ { - "recommendations": [ - "dbaeumer.vscode-eslint", - "GrapeCity.gc-excelviewer", - "ikuyadeu.devreplay", - "DavidAnson.vscode-markdownlint" - ] + "recommendations": [ + "dbaeumer.vscode-eslint", + "GrapeCity.gc-excelviewer", + "ikuyadeu.devreplay", + "DavidAnson.vscode-markdownlint", + "amodio.tsl-problem-matcher" + ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f3d044044..33ce48ea9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -39,7 +39,7 @@ { "type": "npm", "script": "watch", - "problemMatcher": "$tsc-watch", + "problemMatcher": "$ts-checker-eslint-webpack-watch", "isBackground": true, "presentation": { "reveal": "never" From 7cdc68eb5c9dc9a03ff96f0ad855532f042c6dec Mon Sep 17 00:00:00 2001 From: astrochemx <105541001+astrochemx@users.noreply.github.com> Date: Wed, 17 Jul 2024 20:20:22 +0300 Subject: [PATCH 2/6] Fix an error message when the extension cannot find the R path --- src/rTerminal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rTerminal.ts b/src/rTerminal.ts index e527066a7..c40a5b774 100644 --- a/src/rTerminal.ts +++ b/src/rTerminal.ts @@ -141,7 +141,7 @@ export async function createRTerm(preserveshow?: boolean): Promise { const termOptions = await makeTerminalOptions(); const termPath = termOptions.shellPath; if(!termPath){ - void vscode.window.showErrorMessage('Could not find R path. Please check r.term and r.path setting.'); + void vscode.window.showErrorMessage('Could not find R path. Please check r.rterm and r.rpath setting.'); return false; } else if(!fs.existsSync(termPath)){ void vscode.window.showErrorMessage(`Cannot find R client at ${termPath}. Please check r.rterm setting.`); From a4065099735d3d99b1c974ac510de2e1507cc6d1 Mon Sep 17 00:00:00 2001 From: astrochemx <105541001+astrochemx@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:12:00 +0300 Subject: [PATCH 3/6] Fix R terminal attachment when `r.rterm` setting contains only executable file name --- src/util.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/util.ts b/src/util.ts index 2f2ab6b0b..e070c50a3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -41,33 +41,45 @@ export function substituteVariables(str: string): string { return result; } -function getRfromEnvPath(platform: string) { +function getExecutableFromEnvPath(executable: string, platform: string) { let splitChar = ':'; let fileExtension = ''; if (platform === 'win32') { splitChar = ';'; - fileExtension = '.exe'; + if (!executable.toLowerCase().endsWith('.exe')) { + fileExtension = '.exe'; + } } const os_paths: string[] | string = process.env.PATH ? process.env.PATH.split(splitChar) : []; for (const os_path of os_paths) { - const os_r_path: string = path.join(os_path, 'R' + fileExtension); + const os_r_path: string = path.join(os_path, executable + fileExtension); if (fs.existsSync(os_r_path)) { return os_r_path; } } + return ''; } +function ensureAbsolutePath(path: string) { + if (!path.includes('/') && !path.includes('\\')) { + const platform: string = process.platform; + path = getExecutableFromEnvPath(path, platform); + } + + return path; +} + export async function getRpathFromSystem(): Promise { let rpath = ''; const platform: string = process.platform; - rpath ||= getRfromEnvPath(platform); + rpath ||= getExecutableFromEnvPath('R', platform); - if ( !rpath && platform === 'win32') { + if (!rpath && platform === 'win32') { // Find path from registry try { const key = new winreg({ @@ -135,6 +147,7 @@ export async function getRterm(): Promise { const configEntry = getRPathConfigEntry(true); let rpath = config().get(configEntry); rpath &&= substituteVariables(rpath); + rpath &&= ensureAbsolutePath(rpath); rpath ||= await getRpathFromSystem(); if (rpath !== '') { From b62c7d950a2caba5ecc2839bf442831dfb5fe9a4 Mon Sep 17 00:00:00 2001 From: astrochemx <105541001+astrochemx@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:19:33 +0300 Subject: [PATCH 4/6] Switch to the built-in `crypto` module --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index fb6465b2b..8a7cf1c52 100644 --- a/package.json +++ b/package.json @@ -2091,6 +2091,7 @@ "@types/express": "^4.17.12", "@types/fs-extra": "^9.0.11", "@types/glob": "^8.0.0", + "@types/highlight.js": "^10.1.0", "@types/js-yaml": "^4.0.2", "@types/mocha": "^8.2.2", "@types/node": "^18.17.1", @@ -2101,7 +2102,6 @@ "@typescript-eslint/eslint-plugin": "^5.30.0", "@typescript-eslint/parser": "^5.30.0", "@vscode/test-electron": "^2.2.3", - "@types/highlight.js": "^10.1.0", "copy-webpack-plugin": "^9.0.0", "devreplay": "^1.9.31", "eslint": "^7.28.0", @@ -2116,7 +2116,6 @@ "dependencies": { "ag-grid-community": "^31.3.2", "cheerio": "1.0.0-rc.12", - "crypto": "^1.0.1", "ejs": "^3.1.10", "fs-extra": "^10.0.0", "highlight.js": "^11.9.0", From 97b31fd6efe50073342ed989d3f338a61b05eb5a Mon Sep 17 00:00:00 2001 From: astrochemx <105541001+astrochemx@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:35:57 +0300 Subject: [PATCH 5/6] Fix `launch.json` and change `outDir` to `dist` in all places to fix extension debugging in VSCode Also update `settings.json` and fix formatting in some files --- .vscode/launch.json | 8 ++-- .vscode/settings.json | 26 ++++++------ package.json | 2 +- src/liveShare/shareSession.ts | 2 +- src/rmarkdown/preview.ts | 2 - tsconfig.json | 3 +- webpack.config.js | 80 +++++++++++++++++------------------ 7 files changed, 61 insertions(+), 62 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 843bfd69d..2ccdaae81 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,7 @@ "--extensionDevelopmentPath=${workspaceFolder}" ], "outFiles": [ - "${workspaceFolder}/out/src/**/*.js" + "${workspaceFolder}/dist/**/*.js" ], "preLaunchTask": "watchAll" }, @@ -27,7 +27,7 @@ "--disable-extensions" ], "outFiles": [ - "${workspaceFolder}/out/src/**/*.js" + "${workspaceFolder}/dist/**/*.js" ], "preLaunchTask": "watchAll" }, @@ -38,10 +38,10 @@ "runtimeExecutable": "${execPath}", "args": [ "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" + "--extensionTestsPath=${workspaceFolder}/dist/test/suite/index" ], "outFiles": [ - "${workspaceFolder}/out/test/**/*.js" + "${workspaceFolder}/dist/test/**/*.js" ], "preLaunchTask": "npm: pretest" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 6bff3e86f..2bebe5011 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,16 @@ // Place your settings in this file to overwrite default and user settings. { - "files.exclude": { - "out": false // set this to true to hide the "out" folder with the compiled JS files - }, - "search.exclude": { - "out": true // set this to false to include "out" folder in search results - }, - "typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version - "r.lsp.diagnostics": true, - "editor.codeActionsOnSave": { - "source.fixAll.markdownlint": true - } -} \ No newline at end of file + "files.exclude": { + "out": false, // set this to true to hide the "out" folder with the compiled JS files + "dist": false + }, + "search.exclude": { + "out": true, // set this to false to include "out" folder in search results + "dist": true + }, + "typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version + "r.lsp.diagnostics": true, + "editor.codeActionsOnSave": { + "source.fixAll.markdownlint": "explicit" + } +} diff --git a/package.json b/package.json index 8a7cf1c52..b211ce330 100644 --- a/package.json +++ b/package.json @@ -2082,7 +2082,7 @@ "watchHelp": "tsc -p ./html/help --watch", "watchHttpgd": "tsc -p ./html/httpgd --watch", "pretest": "tsc -p ./", - "test": "node ./out/test/runTest.js", + "test": "node ./dist/test/runTest.js", "lint": "eslint src --ext ts" }, "devDependencies": { diff --git a/src/liveShare/shareSession.ts b/src/liveShare/shareSession.ts index d11b930e0..6a6de2d76 100644 --- a/src/liveShare/shareSession.ts +++ b/src/liveShare/shareSession.ts @@ -179,7 +179,7 @@ let panel: vscode.WebviewPanel | undefined = undefined; export async function updateGuestPlot(file: string): Promise { const plotContent = await readContent(file, 'base64'); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - + const guestPlotView: vscode.ViewColumn = asViewColumn(config().get('session.viewers.viewColumn.plot'), vscode.ViewColumn.Two); if (plotContent) { if (panel) { diff --git a/src/rmarkdown/preview.ts b/src/rmarkdown/preview.ts index b9d5984d6..b5b7f8dde 100644 --- a/src/rmarkdown/preview.ts +++ b/src/rmarkdown/preview.ts @@ -5,7 +5,6 @@ import * as cheerio from 'cheerio'; import path = require('path'); import crypto = require('crypto'); - import { config, readContent, setContext, escapeHtml, UriIcon, saveDocument, getRpath, DisposableProcess } from '../util'; import { extensionContext, tmpDir } from '../extension'; import { knitDir } from './knit'; @@ -425,4 +424,3 @@ export class RMarkdownPreviewManager extends RMarkdownManager { void preview.refreshContent(this.useCodeTheme); } } - diff --git a/tsconfig.json b/tsconfig.json index 63715e44e..2f9b26a15 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,8 @@ - { "compilerOptions": { "module": "commonjs", "target": "ES2021", - "outDir": "out", + "outDir": "dist", "lib": [ "ES2021" ], diff --git a/webpack.config.js b/webpack.config.js index 7b4b1feb6..49edc4214 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,48 +6,48 @@ const path = require('path'); const CopyPlugin = require('copy-webpack-plugin'); module.exports = { - target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ + target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ - entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ - output: { + entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ + output: { // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ - path: path.resolve(__dirname, 'dist'), - filename: 'extension.js', - libraryTarget: 'commonjs2', - devtoolModuleFilenameTemplate: '../[resource-path]' - }, - devtool: 'source-map', - externals: { - 'utf-8-validate': 'commonjs utf-8-validate', - bufferutil: 'commonjs bufferutil', - vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ - }, - resolve: { + path: path.resolve(__dirname, 'dist'), + filename: 'extension.js', + libraryTarget: 'commonjs2', + devtoolModuleFilenameTemplate: '../[resource-path]' + }, + devtool: 'source-map', + externals: { + 'utf-8-validate': 'commonjs utf-8-validate', + bufferutil: 'commonjs bufferutil', + vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ + }, + resolve: { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader - extensions: ['.ts', '.js'] - }, - module: { - rules: [ - { - test: /\.ts$/, - exclude: /node_modules/, - use: [ - { - loader: 'ts-loader' - } + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: 'ts-loader' + } + ] + } ] - } - ] - }, - plugins: [ - new CopyPlugin({ - patterns: [ - { from: './node_modules/jquery/dist/jquery.min.js', to: 'resources' }, - { from: './node_modules/jquery.json-viewer/json-viewer', to: 'resources' }, - { from: './node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js', to: 'resources' }, - { from: './node_modules/ag-grid-community/styles/ag-grid.min.css', to: 'resources' }, - { from: './node_modules/ag-grid-community/styles/ag-theme-balham.min.css', to: 'resources' }, - ] - }), - ], + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { from: './node_modules/jquery/dist/jquery.min.js', to: 'resources' }, + { from: './node_modules/jquery.json-viewer/json-viewer', to: 'resources' }, + { from: './node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js', to: 'resources' }, + { from: './node_modules/ag-grid-community/styles/ag-grid.min.css', to: 'resources' }, + { from: './node_modules/ag-grid-community/styles/ag-theme-balham.min.css', to: 'resources' }, + ] + }), + ], }; From 6be35c4b12c9c622ad0920c028f3ca9bf9957e0b Mon Sep 17 00:00:00 2001 From: astrochemx <105541001+astrochemx@users.noreply.github.com> Date: Thu, 18 Jul 2024 02:21:59 +0300 Subject: [PATCH 6/6] Update `yarn.lock` to remove `crypto` package --- yarn.lock | 5 ----- 1 file changed, 5 deletions(-) diff --git a/yarn.lock b/yarn.lock index fa4ca014c..9afdb9e93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1040,11 +1040,6 @@ cross-spawn@^7.0.2, cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" -crypto@^1.0.1: - version "1.0.1" - resolved "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz" - integrity sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig== - css-select@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/css-select/-/css-select-5.1.0.tgz#b8ebd6554c3637ccc76688804ad3f6a6fdaea8a6"