diff --git a/.gitignore b/.gitignore index 5af01e1..cedea92 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,9 @@ lerna-debug.log packages/backend/dummy/main.js # this folder should be initially empty when running the contributor snippet example. -examples/dummy-scripts/.vscode \ No newline at end of file +examples/dummy-scripts/.vscode + +# macOS +.DS_Store + +yarn-error.log \ No newline at end of file diff --git a/packages/backend/README.md b/packages/backend/README.md index a7ec3c1..dc24d11 100644 --- a/packages/backend/README.md +++ b/packages/backend/README.md @@ -1,18 +1,17 @@ -# Code Snippet (Framework) VSCode Extension +# Code Snippet Tool VSCode Extension ## Preview -![form gui screenshot](./resources/preview.png) +![Form GUI Screenshot](./resources/preview.png) -## Description +## Overview -This component is the VSCode extension part of the VSCode Code Snippet Framework. -It is responsible for: +This package is the VSCode extension for the Code Snippet Tool. It enables: -- Loading code snippets contributions (plugins) (e.g [vscode-snippet-contrib](../../examples)). -- Rendering the code snippet form GUI to display relevant questions to the end user: - - inside a [VSCode webview](https://code.visualstudio.com/api/extension-guides/webview). - - Note that the form GUI is developed, in a separate [sub-package](../frontend). -- Bridging between the frontend GUI and the contributions/plugins, e.g: +- Loading code snippet contributions (plugins) for extensibility. +- Rendering a dynamic code snippet form GUI in a [VSCode webview](https://code.visualstudio.com/api/extension-guides/webview) to present relevant questions to users. The form GUI is developed as a separate sub-package. +- Bridging between the frontend GUI and snippet contributions/plugins, including: - Invoking custom validation logic. - - Sending the "answers" of the end user back to the contribution/plugin. + - Sending user-provided answers back to the respective contribution/plugin. + +This architecture supports interactive, extensible code snippet generation in VSCode, combining custom logic with a modern user interface. \ No newline at end of file diff --git a/packages/backend/package.json b/packages/backend/package.json index 06c72b2..5793c6a 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -1,6 +1,6 @@ { - "name": "code-snippet-framework", - "displayName": "Code Snippet", + "name": "code-snippet-tool", + "displayName": "Code Snippet Tool", "version": "2.0.0", "private": true, "description": "A VSCode extension that provides a simple way to add code snippets.", diff --git a/packages/wrapper/.nycrc.json b/packages/wrapper/.nycrc.json new file mode 100644 index 0000000..994596e --- /dev/null +++ b/packages/wrapper/.nycrc.json @@ -0,0 +1,10 @@ +{ + "require": ["ts-node/register/transpile-only"], + "include": ["src/**/*.ts"], + "reporter": ["lcov", "text"], + "extension": [".ts"], + "all": true, + "temp-dir": "./reports/.nyc_output", + "report-dir": "./reports/coverage", + "check-coverage": true +} diff --git a/packages/wrapper/.vscodeignore b/packages/wrapper/.vscodeignore new file mode 100644 index 0000000..14905a8 --- /dev/null +++ b/packages/wrapper/.vscodeignore @@ -0,0 +1,10 @@ +** +!LICENSES +!.reuse +!LICENSE +!README.md +!package.json +!logo.png +!dist/media +!dist/*.js +!resources diff --git a/packages/wrapper/CHANGELOG.md b/packages/wrapper/CHANGELOG.md new file mode 100644 index 0000000..e4d87c4 --- /dev/null +++ b/packages/wrapper/CHANGELOG.md @@ -0,0 +1,4 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. diff --git a/packages/wrapper/README.md b/packages/wrapper/README.md new file mode 100644 index 0000000..5d0da20 --- /dev/null +++ b/packages/wrapper/README.md @@ -0,0 +1,3 @@ +# Code Snippet Wrapper VSCode Extension + +> **Deprecated:** Please use [saposs.code-snippet-tool](https://marketplace.visualstudio.com/items?itemName=saposs.code-snippet-tool) instead. \ No newline at end of file diff --git a/packages/wrapper/logo.png b/packages/wrapper/logo.png new file mode 100644 index 0000000..131cf01 Binary files /dev/null and b/packages/wrapper/logo.png differ diff --git a/packages/wrapper/package.json b/packages/wrapper/package.json new file mode 100644 index 0000000..1e9693f --- /dev/null +++ b/packages/wrapper/package.json @@ -0,0 +1,57 @@ +{ + "name": "code-snippet", + "displayName": "Code Snippet wrapper", + "version": "2.0.0", + "private": true, + "description": "A VSCode extension that provides a simple way to add code snippets.", + "categories": [ + "Other" + ], + "keywords": [ + "code", + "snippet", + "snipping ", + "tool", + "sap" + ], + "bugs": { + "url": "https://github.com/SAP/code-snippet/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/SAP/code-snippet.git" + }, + "license": "Apache 2.0", + "publisher": "SAPOSS", + "main": "./dist/extension", + "scripts": { + "bundle": "webpack --mode production", + "bundle-dev": "webpack --mode development --watch", + "ci": "npm-run-all clean compile coverage bundle package coverage coverage:copy", + "clean": "rimraf ./dist ./coverage *.vsix", + "compile": "tsc -p ./", + "coverage": "nyc mocha -p tsconfig.json --recursive test/**/*.spec.ts", + "coverage:copy": "shx mkdir -p ../../coverage && shx cp -u ./reports/coverage/lcov.info ../../coverage/lcov_backend.info", + "package": "vsce package --yarn .", + "test": "mocha -p tsconfig.json --recursive test/**/*.spec.ts" + }, + "activationEvents": [], + "extensionDependencies": [ + "saposs.code-snippet-tool" + ], + "devDependencies": { + "@types/sinon": "^10.0.11", + "copy-webpack-plugin": "^5.0.5", + "sinon": "^9.2.1", + "string-replace-loader": "^2.1.1", + "ts-loader": "^8.0.14", + "ts-node": "^9.1.1", + "vsce": "^1.73.0", + "webpack": "^5.89.0", + "webpack-cli": "5.1.4" + }, + "engines": { + "vscode": "^1.44.2" + }, + "icon": "logo.png" +} diff --git a/packages/wrapper/src/extension.ts b/packages/wrapper/src/extension.ts new file mode 100644 index 0000000..acfd0a7 --- /dev/null +++ b/packages/wrapper/src/extension.ts @@ -0,0 +1,7 @@ +export function activate(): void { + console.log("Extension activated"); +} + +export function deactivate(): void { + console.log("Extension deactivated"); +} diff --git a/packages/wrapper/test/extension.spec.ts b/packages/wrapper/test/extension.spec.ts new file mode 100644 index 0000000..1830d1d --- /dev/null +++ b/packages/wrapper/test/extension.spec.ts @@ -0,0 +1,26 @@ +import { expect } from "chai"; +import * as sinon from "sinon"; + +import * as extension from "../src/extension"; + +describe("extension unit test", () => { + let sandbox: any; + + before(() => { + sandbox = sinon.createSandbox(); + }); + + after(() => { + sandbox.restore(); + }); + + describe("activate", () => { + it("activation", () => { + expect(extension.activate()).to.be.undefined; + }); + }); + + it("deactivate", () => { + expect(extension.deactivate()).to.be.undefined; + }); +}); diff --git a/packages/wrapper/tsconfig.json b/packages/wrapper/tsconfig.json new file mode 100644 index 0000000..9f4d7a2 --- /dev/null +++ b/packages/wrapper/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "resolveJsonModule": true, + "esModuleInterop": true, + "outDir": "out", + "baseUrl": ".", + // Less strict options due to legacy code - BEGIN + "noImplicitAny": false, + "strictNullChecks": false + // Less strict options due to legacy code - END + }, + "include": ["src/**/*", "test/**/*", "test"] +} diff --git a/packages/wrapper/webpack.config.js b/packages/wrapper/webpack.config.js new file mode 100644 index 0000000..1f94be2 --- /dev/null +++ b/packages/wrapper/webpack.config.js @@ -0,0 +1,42 @@ +"use strict"; + +const path = require("path"); + +const config = { + target: "node", // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ + node: { global: true }, + entry: ["./src/extension.ts"], // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ + devtool: "source-map", + 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]", + }, + externals: { + 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: { + extensions: [".ts", ".js"], + alias: {}, + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: "ts-loader", + options: {}, + }, + ], + }, + ], + }, + optimization: {}, + plugins: [], +}; + +module.exports = config; diff --git a/tsconfig.json b/tsconfig.json index 37f2667..aa91d61 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,9 @@ { "path": "./packages/backend" }, + { + "path": "./packages/wrapper" + }, { "path": "./packages/types" },