Skip to content

Commit

Permalink
Merge branch 'main' into last-rstudioapi-shims-i-hope
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Silge <julia.silge@gmail.com>
  • Loading branch information
juliasilge authored Apr 2, 2024
2 parents 8df207d + aa2727f commit ca5ada0
Show file tree
Hide file tree
Showing 72 changed files with 5,816 additions and 1,172 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/positron-python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
branches:
- main
paths:
- '.github/workflows/positron-python-ci.yml'
- 'extensions/positron-python/**'
pull_request:
branches:
- main
paths:
- '.github/workflows/positron-python-ci.yml'
- 'extensions/positron-python/**'


Expand Down Expand Up @@ -196,18 +198,18 @@ jobs:
- os: 'ubuntu-latest'
python: '3.12'
time-elapsed: ''
- os: 'ubuntu-latest'
python: '3.10'
time-elapsed: '3 months'
- os: 'ubuntu-latest'
python: '3.10'
time-elapsed: '6 months'
- os: 'ubuntu-latest'
python: '3.10'
time-elapsed: '9 months'
- os: 'ubuntu-latest'
python: '3.10'
time-elapsed: '1 year'
# - os: 'ubuntu-latest'
# python: '3.10'
# time-elapsed: '3 months'
# - os: 'ubuntu-latest'
# python: '3.10'
# time-elapsed: '6 months'
# - os: 'ubuntu-latest'
# python: '3.10'
# time-elapsed: '9 months'
# - os: 'ubuntu-latest'
# python: '3.10'
# time-elapsed: '1 year'

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const compilations = [
'positron-connections/tsconfig.json',
'positron-javascript/tsconfig.json',
'positron-notebook-controllers/tsconfig.json',
'positron-notebooks/tsconfig.json',
'positron-r/tsconfig.json',
'positron-rstudio-keymap/tsconfig.json',
'positron-python/tsconfig.json',
Expand Down
1 change: 1 addition & 0 deletions build/npm/dirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const dirs = [
'extensions/positron-connections',
'extensions/positron-javascript',
'extensions/positron-notebook-controllers',
'extensions/positron-notebooks',
'extensions/positron-r',
'extensions/positron-rstudio-keymap',
'extensions/positron-python',
Expand Down
20 changes: 20 additions & 0 deletions extensions/positron-notebooks/extension.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

//@ts-check

'use strict';

const withDefaults = require('../shared.webpack.config');

module.exports = withDefaults({
context: __dirname,
entry: {
extension: './src/extension.ts',
},
externals: {
'vscode': { commonjs: 'vscode' },
'express': { commonjs: 'express' }
}
});
50 changes: 50 additions & 0 deletions extensions/positron-notebooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "positron-notebooks-helpers",
"displayName": "Positron Notebooks Helpers",
"description": "Positron Notebook Helpers",
"version": "1.0.0",
"publisher": "vscode",
"engines": {
"vscode": "^1.65.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onStartupFinished"
],
"contributes": {
"commands": [
{
"command": "positronNotebookHelpers.convertImageToBase64",
"title": "Convert Image to Base64"
}
]
},
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"lint": "eslint src --ext ts"
},
"dependencies": {},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.0",
"@types/node": "14.x",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@vscode/test-electron": "^2.1.2",
"eslint": "^8.9.0",
"glob": "^7.2.0",
"mocha": "^9.2.1",
"ts-node": "^10.9.1",
"typescript": "^4.5.5",
"vsce": "^2.11.0"
},
"repository": {
"type": "git",
"url": "https://github.com/posit-dev/positron"
}
}
82 changes: 82 additions & 0 deletions extensions/positron-notebooks/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

import path from 'path';
import * as vscode from 'vscode';
import { readFile } from 'fs';

// Make sure this matches the error message type defined where used
// (src/vs/workbench/contrib/positronNotebook/browser/notebookCells/DeferredImage.tsx)
type CoversionErrorMsg = {
status: 'error';
message: string;
};

/**
* Activates the extension.
* @param context An ExtensionContext that contains the extention context.
*/
export function activate(context: vscode.ExtensionContext) {
// Command that converts an image from the local file-system to a base64 string.
context.subscriptions.push(
vscode.commands.registerCommand(
'positronNotebookHelpers.convertImageToBase64',
async (imageSrc: string, baseLoc: string) => new Promise<string | CoversionErrorMsg>((resolve) => {
const fullImagePath = path.join(baseLoc, imageSrc);
const fileExtension = path.extname(imageSrc).slice(1);
const mimeType = mimeTypeMap[fileExtension.toLowerCase()];
if (!mimeType) {
resolve({
status: 'error',
message: `Unsupported file type: "${fileExtension}."`,
});
return;
}
try {
readFile(fullImagePath, (err, data) => {
if (err) {
resolve({
status: 'error',
message: err.message,
});
} else if (!data) {
resolve({
status: 'error',
message: `No data found in file "${fullImagePath}."`,
});
} else {
resolve(`data:${mimeType};base64,${data.toString('base64')}`);
}
});
} catch (e) {
return {
type: 'error',
message: e instanceof Error ? e.message : `Error occured while converting image ${fullImagePath} to base64.`,
};
}
})
)
);
}


/**
* Map image file extension to MIME type.
*
* Supports all the 'image' types from [this list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
*/
const mimeTypeMap: Record<string, string> = {
png: 'image/png',
apng: 'image/apng',
avif: 'image/avif',
ico: 'image/vnd.microsoft.icon',
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
gif: 'image/gif',
bmp: 'image/bmp',
webp: 'image/webp',
svg: 'image/svg+xml',
tiff: 'image/tiff',
tif: 'image/tiff',
};
17 changes: 17 additions & 0 deletions extensions/positron-notebooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"outDir": "out",
"esModuleInterop": true,
"lib": ["ES2020"],
"sourceMap": true,
"rootDir": "src",
"strict": true,
"typeRoots": ["./node_modules/@types"],
"paths": {
"*": ["./node_modules/*"]
}
},
"include": ["src/**/*", "../../src/vscode-dts/vscode.d.ts"]
}
Loading

0 comments on commit ca5ada0

Please sign in to comment.