diff --git a/.vscode/launch.json b/.vscode/launch.json index 6e4eca5..2ea7cbd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -31,8 +31,8 @@ "preLaunchTask": "npm: test-watch" }, { - "name": "Extension Tests in VS Code Web", - "type": "extensionHost", + "name": "Web Extension Tests", + "type": "pwa-extensionHost", "request": "launch", "debugWebWorkerHost": true, "args": [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 02dab86..5845b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ ## Known issues - notebook search with `m` or `y` in key won't work, as vscode configured default shortcut `m` to change cell to markdown and is annoying. [remove](https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-shortcuts-editor) `m` and `y` shortcuts for clean experience. +## [0.0.42] +- [**Improvement**] NTLM auth suggestions and other +- [**Improvements**] Notebook + - Generate curl/code from cell itself + - Now output of cell creates new presentation view for most used content types (simple view) + - Actions to Reveal history/Variables view && Restart cli with ease +- [**Bug**] web extension show commands only which works +- [**Bug**] Earlier history is always recorded. now it respsects configuration ## [0.0.41] - [**Improvement**] New Walkthroughs to setup dothttp easily diff --git a/package-lock.json b/package-lock.json index d573ea4..24c2368 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dothttp-code", - "version": "0.0.41", + "version": "0.0.42", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index c1ab781..ca984d4 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "dothttp-code", - "displayName": "Dothttp Http Client", + "displayName": "Dothttp", "description": "A Http Client for sending to and receiving from http endpoints (dothttp)", - "version": "0.0.41", + "version": "0.0.42", "license": "Apache-2.0", "publisher": "shivaprasanth", "repository": { @@ -159,206 +159,285 @@ "commands": [ { "command": "dothttp.command.newHttpBook", - "title": "New Notebook", + "title": "Notebook", + "shortTitle": "Dothttp Notebook", "icon": "$(notebook)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.newHttpFile", - "title": "New Http File", - "category": "Dothttp" + "title": "File", + "shortTitle": "Dothttp File", + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.run", "title": "Run Target", "icon": "$(rocket)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.notebook.run", "title": "Run Target in Notebook", "icon": "$(rocket)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.text.run", "title": "Run Target CodeLens", "icon": "$(rocket)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.gencurl", "title": "Generate Curl", "icon": "$(mirror)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.reuse", "title": "Toggles Reuse Tab Setting", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.runrecent", "title": "Toggles Run Recent Setting", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.experimental", "title": "Toggles Experimental Setting", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.showheaders", "title": "Toggles Showheaders Setting", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.history", "title": "Toggles History Setting", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.nocookie", "title": "Toggles Cookie Setting", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.toggle.unstable", "title": "Toggles Unstable dothttp build", "category": "Dothttp", - "icon": "$(gear)" + "icon": "$(gear)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.import.external", "title": "Dothttp: Import Resource To Http", "category": "Dothttp", - "icon": "$(cloud-download)" + "icon": "$(cloud-download)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpEnvView.refresh", "title": "Refresh", - "icon": "$(refresh)" + "icon": "$(refresh)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpEnvView.enableenv", "title": "Enable Environment", - "icon": "$(add)" + "icon": "$(add)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpEnvView.disableenv", "title": "Disable Environment", - "icon": "$(remove)" + "icon": "$(remove)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.add", "title": "Add Property", - "icon": "$(new-file)" + "icon": "$(new-file)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.enableproperty", "title": "Enable Property", - "icon": "$(add)" + "icon": "$(add)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.disableproperty", "title": "Disable Property", - "icon": "$(remove)" + "icon": "$(remove)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.copyPropertyValue", "title": "Copy Property Value", - "icon": "$(chrome-restore)" + "icon": "$(chrome-restore)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.updateproperty", "title": "Update Property", - "icon": "$(edit)" + "icon": "$(edit)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.disableAllProperties", "title": "Disable All Properties", - "icon": "$(close-all)" + "icon": "$(close-all)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpEnvView.disableAllEnv", "title": "Disable All Environment", - "icon": "$(close-all)" + "icon": "$(close-all)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpPropView.removeproperty", "title": "Remove Property", - "icon": "$(trash)" + "icon": "$(trash)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpEnvView.opendothttpjson", "title": "Open", - "icon": "$(edit)" + "icon": "$(edit)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttpEnvView.copyPropertyValue", "title": "Copy Environment Value", - "icon": "$(chrome-restore)" + "icon": "$(chrome-restore)", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.generatelang", "title": "Dothttp: Generate General Programming Languages For Request", "icon": "$(extensions)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.restartcli", "title": "Restart Cli Server", "icon": "$(debug-restart)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.export.postman", "title": "Dothttp: Export Http To Postman", "icon": "$(extensions)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.notebook.tohttpfile", "title": "Dothttp: Notebook To Httpfile", "icon": "$(archive)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" }, { "command": "dothttp.command.openAsHttpBook", "title": "Dothttp: Open as a Httpbook", "icon": "$(book)", - "category": "Dothttp" + "category": "Dothttp", + "enablement": "dothttpRunMode == full" + }, + { + "command": "dothttp.command.openVariableView", + "title": "Reveal Vairables", + "icon": "$(eye)", + "category": "Dothttp", + "enablement": "dothttpRunMode == full" + }, + { + "command": "dothttp.command.notebook.prog", + "title": "Generate Code", + "icon": "$(mirror)", + "category": "Dothttp", + "enablement": "dothttpRunMode == full" + }, + { + "command": "dothttp.command.notebook.gencurl", + "title": "Generate Quick Curl", + "icon": "$(mirror)", + "category": "Dothttp", + "enablement": "dothttpRunMode == full" } ], "menus": { + "notebook/toolbar": [ + { + "command": "dothttp.command.restartcli", + "when": "dothttpRunMode == full && notebookType == 'dothttp-book'", + "group": "navigation/execute@1" + }, + { + "command": "dothttp.command.openVariableView", + "when": "dothttpRunMode == full && notebookType == 'dothttp-book'", + "group": "navigation/execute@2" + } + ], + "notebook/cell/execute": [ + { + "command": "dothttp.command.notebook.prog", + "when": "dothttpRunMode == full && notebookType == 'dothttp-book'" + }, + { + "command": "dothttp.command.notebook.gencurl", + "when": "dothttpRunMode == full && notebookType == 'dothttp-book'" + } + ], "file/newFile": [ { - "command": "dothttp.command.newHttpBook" + "command": "dothttp.command.newHttpBook", + "when": "dothttpRunMode == full" }, { - "command": "dothttp.command.newHttpFile" + "command": "dothttp.command.newHttpFile", + "when": "dothttpRunMode == full" } ], "editor/title": [ { "command": "dothttp.command.run", - "when": "resourceExtname == .http || resourceExtname == .dhttp", + "when": "(resourceExtname == .http || resourceExtname == .dhttp) && dothttpRunMode == full", "group": "navigation@1" }, { "command": "dothttp.command.gencurl", - "when": "resourceExtname == .http || resourceExtname == .dhttp", + "when": "(resourceExtname == .http || resourceExtname == .dhttp) && dothttpRunMode == full", "group": "navigation@2" }, { "command": "dothttp.command.notebook.tohttpfile", - "when": "resourceExtname == .httpbook || resourceExtname == .hnbk", + "when": "(resourceExtname == .httpbook || resourceExtname == .hnbk) && dothttpRunMode == full", "group": "navigation@1" } ], @@ -367,76 +446,103 @@ "command": "dothttp.command.export.postman", "title": "Export http to postman", "group": "Export", - "icon": "$(extensions)" + "icon": "$(extensions)", + "when": "dothttpRunMode == full" + }, + { + "command": "dothttp.command.openVariableView", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.import.external", "title": "Dothttp: Import Resource To Http", "group": "Import", - "icon": "$(cloud-download)" + "icon": "$(cloud-download)", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.generatelang", "title": "Generate General Programming Languages For Request", "group": "Export", "icon": "$(extensions)", - "when": "resourceLangId == 'dothttp-vscode'" + "when": "resourceLangId == 'dothttp-vscode' && dothttpRunMode == full" }, { "command": "dothttp.command.run", "title": "Run Target", "icon": "$(rocket)", "group": "Dothttp", - "when": "resourceLangId == 'dothttp-vscode'" + "when": "resourceLangId == 'dothttp-vscode' && dothttpRunMode == full" }, { "command": "dothttp.command.openAsHttpBook", "title": "Open as a Httpbook", "icon": "$(book)", "group": "Export", - "when": "resourceLangId == 'dothttp-vscode'" + "when": "resourceLangId == 'dothttp-vscode' && dothttpRunMode == full" } ], "commandPalette": [ { "group": "toggle", - "command": "dothttp.command.toggle.reuse" + "command": "dothttp.command.toggle.reuse", + "when": "dothttpRunMode == full" + }, + { + "command": "dothttp.command.openVariableView", + "when": "never" + }, + { + "command": "dothttp.command.notebook.prog", + "when": "never" + }, + { + "command": "dothttp.command.notebook.gencurl", + "when": "never" }, { "group": "toggle", - "command": "dothttp.command.toggle.runrecent" + "command": "dothttp.command.toggle.runrecent", + "when": "dothttpRunMode == full" }, { "group": "dothttp", - "command": "dothttp.command.newHttpBook" + "command": "dothttp.command.newHttpBook", + "when": "dothttpRunMode == full" }, { "group": "dothttp", - "command": "dothttp.command.newHttpFile" + "command": "dothttp.command.newHttpFile", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.run", - "when": "resourceExtname == .http || resourceExtname == .dhttp" + "when": "(resourceExtname == .http || resourceExtname == .dhttp) && dothttpRunMode == full" }, { "group": "toggle", - "command": "dothttp.command.toggle.experimental" + "command": "dothttp.command.toggle.experimental", + "when": "dothttpRunMode == full" }, { "group": "toggle", - "command": "dothttp.command.toggle.nocookie" + "command": "dothttp.command.toggle.nocookie", + "when": "dothttpRunMode == full" }, { "group": "toggle", - "command": "dothttp.command.toggle.history" + "command": "dothttp.command.toggle.history", + "when": "dothttpRunMode == full" }, { "group": "toggle", - "command": "dothttp.command.toggle.showheaders" + "command": "dothttp.command.toggle.showheaders", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.openAsHttpBook", - "group": "export" + "group": "export", + "when": "dothttpRunMode == full" }, { "command": "dothttpEnvView.enableenv", @@ -496,15 +602,18 @@ }, { "command": "dothttp.command.export.postman", - "group": "export" + "group": "export", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.import.external", - "group": "export" + "group": "export", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.generatelang", - "group": "export" + "group": "export", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.notebook.run", @@ -550,19 +659,20 @@ { "command": "dothttp.command.export.postman", "title": "Export Http To Postman", - "icon": "$(extensions)" + "icon": "$(extensions)", + "when": "dothttpRunMode == full" }, { "command": "dothttp.command.generatelang", "title": "Generate General Programming Languages For Request", "icon": "$(book)", - "when": "resourceLangId == 'dothttp-vscode'" + "when": "resourceLangId == 'dothttp-vscode' && dothttpRunMode == full" }, { "command": "dothttp.command.openAsHttpBook", "title": "Open as a Httpbook", "icon": "$(book)", - "when": "resourceLangId == 'dothttp-vscode'" + "when": "resourceLangId == 'dothttp-vscode' && dothttpRunMode == full" } ], "view/item/context": [ @@ -640,7 +750,7 @@ "dothttp.conf.path": { "type": "string", "default": "/usr/bin/dothttp", - "description": "dothttp installation location" + "description": "Dothttp Installation Location" }, "dothttp.conf.experimental": { "type": "boolean", @@ -654,18 +764,13 @@ }, "dothttp.conf.history": { "type": "boolean", - "default": false, + "default": true, "description": "Save history of requests by setting to `ture`" }, - "dothttp.conf.curl": { - "type": "boolean", - "default": false, - "description": "Genererate curl command only!" - }, "dothttp.conf.showheaders": { "type": "boolean", "default": false, - "description": "Show headers in seperate view" + "description": "Show Headers In Seperate View" } }, "label": "dothttp", @@ -689,7 +794,8 @@ }, { "id": "dothttpHistory", - "name": "Dothttp history" + "name": "Dothttp history", + "when": "dothttpRunMode == full" } ] }, @@ -781,4 +887,4 @@ "uuid": "^8.3.2", "whatwg-url": "^8.5.0" } -} +} \ No newline at end of file diff --git a/src/extension/commands/export/generate.ts b/src/extension/commands/export/generate.ts index fb814e8..d040bcb 100644 --- a/src/extension/commands/export/generate.ts +++ b/src/extension/commands/export/generate.ts @@ -7,7 +7,7 @@ import { cacheAndGetTarget, showEditor } from '../run'; import HTTPSnippet = require("httpsnippet"); import { QuickPickItem } from 'vscode'; -const LANG_GEN_TARGETS: Array, filext?: string, description?: string }> = [ +export const LANG_GEN_TARGETS: Array, filext?: string, description?: string }> = [ { label: "python", options: ["requests", "python3",], filext: ".py", description: "python :(requests, python3)", }, { label: "node", options: ["fetch", "axios", "native", "request", "unirest"], filext: ".js", description: "node: (fetch, axios, native, request, unirest)" }, { label: "javascript", options: ["fetch", "axios", "jquery", "xhr"], filext: ".js", description: "javascript: (fetch, axios, jquery, xhr)" }, @@ -42,7 +42,7 @@ export async function generateLangForHttpFile(uri: vscode.Uri) { } -export async function generateLang(options: { filename: string, target: string, content?: string }): Promise { +export async function generateLangFromOptions(options: { filename: string, target: string, content?: string }): Promise<{ code: string, language: string, error: false } | void> { const { filename, target, content } = options; const clientHanler = ApplicationServices.get().getClientHandler(); const fileStateService = ApplicationServices.get().getFileStateService(); @@ -56,6 +56,9 @@ export async function generateLang(options: { filename: string, target: string, env: fileStateService.getEnv(filename)! ?? [], }); try { + if (out.error) { + return + } const targetHttpDef = out.target[target ?? '1']! as HttpTargetDef; const snippet = new HTTPSnippet({ method: targetHttpDef.method, url: targetHttpDef.url, @@ -76,14 +79,30 @@ export async function generateLang(options: { filename: string, target: string, const langSpec = snippet.convert(pickLanguage.label!, pickImpl, { indent: '\t' }); - // TODO only gives out python file name now. - const outputBodyURI = vscode.Uri.parse("untitled:" + filename + ".gen" + pickLanguage.filext); - vscode.workspace.openTextDocument(outputBodyURI).then((textDoc) => { - showEditor(textDoc, langSpec as string); - }); + if (langSpec) { + return { "code": langSpec as string, "language": pickLanguage.label, error: false } + } return; + } catch (error) { console.log(error); } return; } + + + +export async function generateLang(options: { filename: string, target: string, content?: string }): Promise { + try { + const langSpec = await generateLangFromOptions(options) + if (langSpec && !langSpec.error) { + const outputBodyURI = vscode.Uri.parse("untitled:" + options.filename + ".gen" + langSpec.language); + vscode.workspace.openTextDocument(outputBodyURI).then((textDoc) => { + showEditor(textDoc, langSpec.code as string); + }); + } + } catch (error) { + console.log(error); + } + return; +} diff --git a/src/extension/commands/run.ts b/src/extension/commands/run.ts index b307cac..b39c383 100644 --- a/src/extension/commands/run.ts +++ b/src/extension/commands/run.ts @@ -180,17 +180,20 @@ function getBaseFileNameToSave(config: Configuration, filename: string) { } export function addHistory(out: any, filename: string, options: { target: string; }) { - const history = { - url: out.url as string, - http: out.http as string, - filename: filename as string, - target: options.target as string, - time: new Date(), - status_code: out.status as number - }; - ApplicationServices.get().getHistoryService().addNew( - history); - ApplicationServices.get().getHistoryTreeProvider().recentChanged(history); + if (ApplicationServices.get().getConfig().history) { + const history = { + url: out.url as string, + http: out.http as string, + filename: filename as string, + target: options.target as string, + time: new Date(), + status_code: out.status as number + }; + ApplicationServices.get().getHistoryService().addNew( + history); + ApplicationServices.get().getHistoryTreeProvider().recentChanged(history); + } + } export function showInUntitledView(scriptFileName: string, headerURI: string, out: DothttpExecuteResponse) { diff --git a/src/extension/extension.ts b/src/extension/extension.ts index 9f70ae4..c6e62ce 100644 --- a/src/extension/extension.ts +++ b/src/extension/extension.ts @@ -21,6 +21,8 @@ export async function activate(context: vscode.ExtensionContext) { if (!vscode.workspace.isTrusted) { webExtensionActivate(context); return + } else { + vscode.commands.executeCommand('setContext', Constants.EXTENSION_RUN_MODE, "full"); } await bootStrap(context); @@ -61,6 +63,16 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand(Constants.IMPORT_RESOURCE_COMMAND, importRequests), vscode.commands.registerCommand(Constants.EXPORT_RESOURCE_COMMAND, exportToPostman), vscode.commands.registerCommand(Constants.GENERATE_PROG_LANG_COMMAND, generateLangForHttpFile), + + vscode.commands.registerCommand(Constants.NOTEBOOK_CELL_GEN_CURL, async (cell) => + ApplicationServices.get().getNotebookkernel().generateCurl(cell) + ), + vscode.commands.registerCommand(Constants.NOTEBOOK_CELL_GEN_PROGRAM, async (cell) => + ApplicationServices.get().getNotebookkernel().generateProgrammingLang(cell) + ), + vscode.commands.registerCommand(Constants.REVEAL_HISTORY_VIEW, () => { + vscode.commands.executeCommand('dothttpHistory.focus'); + }), vscode.commands.registerCommand(Constants.RESTART_CLI_COMMAND, () => { appServices.getClientHandler().restart(); }), @@ -68,8 +80,8 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand(Constants.HTTPBOOK_SAVE_AS_HTTP, saveNotebookAsHttpFileFromCommand), vscode.workspace.registerTextDocumentContentProvider(DotHttpEditorView.scheme, appServices.getDotHttpEditorView()), vscode.commands.registerCommand(Constants.HTTP_AS_HTTPBOOK, saveHttpFileasNotebook), - vscode.commands.registerCommand(Constants.NEW_NOTEBOOK_COMMAND, ()=>createNewNotebook(FileTypes.DotNotebook)), - vscode.commands.registerCommand(Constants.NEW_HTTP_FILE_COMMAND, ()=>createNewNotebook(FileTypes.DotHttp)) + vscode.commands.registerCommand(Constants.NEW_NOTEBOOK_COMMAND, () => createNewNotebook(FileTypes.DotNotebook)), + vscode.commands.registerCommand(Constants.NEW_HTTP_FILE_COMMAND, () => createNewNotebook(FileTypes.DotHttp)) ]) diff --git a/src/extension/lib/lang-parse.ts b/src/extension/lib/lang-parse.ts index bcf5196..7538275 100644 --- a/src/extension/lib/lang-parse.ts +++ b/src/extension/lib/lang-parse.ts @@ -31,4 +31,5 @@ export interface Param { export interface HttpFileTargetsDef { target: Targets; + error: boolean } diff --git a/src/extension/models/config.ts b/src/extension/models/config.ts index c2de55e..cf7e901 100644 --- a/src/extension/models/config.ts +++ b/src/extension/models/config.ts @@ -88,6 +88,7 @@ export class Configuration { showHeaders = false; noCookies = false; isExperimental = false; + history = true; configchange = vscode.workspace.onDidChangeConfiguration(() => this.update()); pythonPath!: string; dothttpPath!: string; @@ -107,6 +108,7 @@ export class Configuration { this.pythonPath = vsCodeconfig.get(Constants.pythonPath) as string; this.dothttpPath = vsCodeconfig.get(Constants.dothttpPath) as string; this.responseSaveDirectory = vsCodeconfig.get(Constants.responseDirectory) as string; + this.history = vsCodeconfig.get(Constants.history) as boolean; } public update() { diff --git a/src/extension/models/constants.ts b/src/extension/models/constants.ts index 273c2c1..f3c5f5e 100644 --- a/src/extension/models/constants.ts +++ b/src/extension/models/constants.ts @@ -1,90 +1,97 @@ export enum Constants { - // to notify, these all should be in caps - LANG_CODE = 'dothttp-vscode', - - // configs - pythonPath = "dothttp.conf.pythonpath", - dothttpPath = "dothttp.conf.path", - experimental = "dothttp.conf.experimental", - nocookie = "dothttp.conf.nocookie", - history = "dothttp.conf.history", - curl = "dothttp.conf.curl", - showheaders = "dothttp.conf.showheaders", - runConf = "dothttp.conf.runrecent", - reUseOldTab = "dothttp.conf.run.reuseold", - responseDirectory = "dothttp.conf.response.savedirectory", - CONFIG_DOTHTTP_USE_STABLE = "dothttp.conf.useunstable", - // view props - // commands - RUN_FILE_COMMAND = 'dothttp.command.run', - GEN_CURL_FILE_COMMAND = 'dothttp.command.gencurl', - toggleExperimentalCommand = "dothttp.command.toggle.experimental", - toggleHistoryCommand = "dothttp.command.toggle.history", - toggleNocookieCommand = "dothttp.command.toggle.nocookie", - toggleHeadersCommand = "dothttp.command.toggle.showheaders", - toggleReuseTabCommand = "dothttp.command.toggle.runrecent", - toggleRunRecentCommand = "dothttp.command.toggle.reuse", - COMMAND_TOGGLE_UNSTABLE = "dothttp.command.toggle.unstable", - IMPORT_RESOURCE_COMMAND = "dothttp.command.import.external", - EXPORT_RESOURCE_COMMAND = "dothttp.command.export.postman", - GENERATE_PROG_LANG_COMMAND = "dothttp.command.generatelang", - RESTART_CLI_COMMAND = "dothttp.command.restartcli", - RUN_NOTEBOOK_TARGET_IN_CELL = "dothttp.command.codelens.notebook.run", - RUN_TARGET_CODE_LENS = "dothttp.command.text.run", - - HTTPBOOK_SAVE_AS_HTTP = "dothttp.command.notebook.tohttpfile", + // to notify, these all should be in caps + LANG_CODE = 'dothttp-vscode', + + // configs + pythonPath = "dothttp.conf.pythonpath", + dothttpPath = "dothttp.conf.path", + experimental = "dothttp.conf.experimental", + nocookie = "dothttp.conf.nocookie", + history = "dothttp.conf.history", + showheaders = "dothttp.conf.showheaders", + runConf = "dothttp.conf.runrecent", + reUseOldTab = "dothttp.conf.run.reuseold", + responseDirectory = "dothttp.conf.response.savedirectory", + CONFIG_DOTHTTP_USE_STABLE = "dothttp.conf.useunstable", + // view props + // commands + RUN_FILE_COMMAND = 'dothttp.command.run', + GEN_CURL_FILE_COMMAND = 'dothttp.command.gencurl', + toggleExperimentalCommand = "dothttp.command.toggle.experimental", + toggleHistoryCommand = "dothttp.command.toggle.history", + toggleNocookieCommand = "dothttp.command.toggle.nocookie", + toggleHeadersCommand = "dothttp.command.toggle.showheaders", + toggleReuseTabCommand = "dothttp.command.toggle.runrecent", + toggleRunRecentCommand = "dothttp.command.toggle.reuse", + COMMAND_TOGGLE_UNSTABLE = "dothttp.command.toggle.unstable", + IMPORT_RESOURCE_COMMAND = "dothttp.command.import.external", + EXPORT_RESOURCE_COMMAND = "dothttp.command.export.postman", + GENERATE_PROG_LANG_COMMAND = "dothttp.command.generatelang", + RESTART_CLI_COMMAND = "dothttp.command.restartcli", + RUN_NOTEBOOK_TARGET_IN_CELL = "dothttp.command.codelens.notebook.run", + RUN_TARGET_CODE_LENS = "dothttp.command.text.run", + REVEAL_HISTORY_VIEW = "dothttp.command.openVariableView", + + HTTPBOOK_SAVE_AS_HTTP = "dothttp.command.notebook.tohttpfile", + + NOTEBOOK_CELL_GEN_CURL = "dothttp.command.notebook.gencurl", + NOTEBOOK_CELL_GEN_PROGRAM = "dothttp.command.notebook.prog", + HTTP_AS_HTTPBOOK = "dothttp.command.openAsHttpBook", - NEW_NOTEBOOK_COMMAND = "dothttp.command.newHttpBook", - NEW_HTTP_FILE_COMMAND = "dothttp.command.newHttpFile", - + NEW_NOTEBOOK_COMMAND = "dothttp.command.newHttpBook", + NEW_HTTP_FILE_COMMAND = "dothttp.command.newHttpFile", - // env tree - envTreeView = 'dothttpEnvView', + // env tree + envTreeView = 'dothttpEnvView', - // history tree - dothttpHistory = "dothttpHistory", - refreshEnvCommand = 'dothttpEnvView.refresh', - enableEnvCommand = 'dothttpEnvView.enableenv', - disableEnvCommand = 'dothttpEnvView.disableenv', - copyEnvValueCommand = 'dothttpEnvView.copyPropertyValue', - openEnvFileCommmand = 'dothttpEnvView.opendothttpjson', - disableAllEnvCommmand = "dothttpEnvView.disableAllEnv", + // history tree + dothttpHistory = "dothttpHistory", + refreshEnvCommand = 'dothttpEnvView.refresh', + enableEnvCommand = 'dothttpEnvView.enableenv', + disableEnvCommand = 'dothttpEnvView.disableenv', + copyEnvValueCommand = 'dothttpEnvView.copyPropertyValue', + openEnvFileCommmand = 'dothttpEnvView.opendothttpjson', + disableAllEnvCommmand = "dothttpEnvView.disableAllEnv", - enableEnvViewVar = 'dothttpEnvViewEnabled', + enableEnvViewVar = 'dothttpEnvViewEnabled', - notebookscheme = "vscode-notebook-cell", - // proptree - propTreeView = 'dothttpPropView', + notebookscheme = "vscode-notebook-cell", - addPropCommand = 'dothttpPropView.add', - enablePropCommand = 'dothttpPropView.enableproperty', - disablePropCommand = 'dothttpPropView.disableproperty', - copyEnvPropCommand = 'dothttpPropView.copyPropertyValue', - updatePropCommand = 'dothttpPropView.updateproperty', - removePropCommand = "dothttpPropView.removeproperty", - disableAllPropCommand = "dothttpPropView.disableAllProperties", - // tree vars - propViewEnabled = "dothttpPropViewEnabled", + // proptree + propTreeView = 'dothttpPropView', + addPropCommand = 'dothttpPropView.add', + enablePropCommand = 'dothttpPropView.enableproperty', + disablePropCommand = 'dothttpPropView.disableproperty', + copyEnvPropCommand = 'dothttpPropView.copyPropertyValue', + updatePropCommand = 'dothttpPropView.updateproperty', + removePropCommand = "dothttpPropView.removeproperty", + disableAllPropCommand = "dothttpPropView.disableAllProperties", + // tree vars + propViewEnabled = "dothttpPropViewEnabled", - NOTEBOOK_MIME_TYPE = "x-application/dotbook", + EXTENSION_RUN_MODE = "dothttpRunMode", - NOTEBOOK_ID = 'dothttp-book', + NOTEBOOK_MIME_TYPE = "x-application/dotbook", - // download stuff - EXTENSION_VERSION = "0.0.41", - dothttpNotebook = "dothttp-book", + NOTEBOOK_ID = 'dothttp-book', - dothttpVersion = "dothttp.version", + // download stuff + EXTENSION_VERSION = "0.0.42", - versionApi = "https://raw.githubusercontent.com/cedric05/dothttp-runner/VERSION/version.json", - SECRET_POSTMAN_API_KEY = "POSTMAN_API_KEY" + dothttpNotebook = "dothttp-book", + + dothttpVersion = "dothttp.version", + + versionApi = "https://raw.githubusercontent.com/cedric05/dothttp-runner/VERSION/version.json", + SECRET_POSTMAN_API_KEY = "POSTMAN_API_KEY", + } diff --git a/src/extension/services/dothttpCompletion.ts b/src/extension/services/dothttpCompletion.ts index 7c2617d..a668588 100644 --- a/src/extension/services/dothttpCompletion.ts +++ b/src/extension/services/dothttpCompletion.ts @@ -136,6 +136,7 @@ export class VariableCompletionProvider implements CompletionItemProvider { static readonly randomSuggesstionsList: ReadonlyArray = ["$randomStr", + "$randomFloat", "$guid", "$randomLoremSlug", "$randomInt", "$randomBool", "$randomSlug", "$uuid", "$timestamp"] @@ -247,6 +248,7 @@ export class KeywordCompletionItemProvider implements CompletionItemProvider { "json", "urlencoded", "files", + "file", "multipart", "text", "form", @@ -254,15 +256,17 @@ export class KeywordCompletionItemProvider implements CompletionItemProvider { "fileinput", "digestauth", "ntlmauth", - "cert", + "key", "p12", "certificate", "cert", "password", "@insecure", "@name(", - "@clear" - + "@clear", + "header", + "query", + "output" ]; provideCompletionItems(document: TextDocument, position: Position, _token: CancellationToken, _context: CompletionContext): ProviderResult> { diff --git a/src/extension/services/notebook.ts b/src/extension/services/notebook.ts index 9e5df8c..bc591b3 100644 --- a/src/extension/services/notebook.ts +++ b/src/extension/services/notebook.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; import { DothttpExecuteResponse, MessageType, NotebookExecutionMetadata, Response } from '../../common/response'; -import { generateLang } from "../commands/export/generate"; +import { generateLang, generateLangFromOptions } from "../commands/export/generate"; import { addHistory, contructFileName, showInUntitledView } from '../commands/run'; import { ClientHandler } from "../lib/client"; import { Constants } from "../models/constants"; @@ -26,7 +26,7 @@ export class NotebookKernel { Constants.dothttpNotebook, 'Dothttp Book'); - this._controller.supportedLanguages = [Constants.LANG_CODE]; + this._controller.supportedLanguages = [Constants.LANG_CODE, "python"]; this._controller.supportsExecutionOrder = true; this._controller.description = 'A notebook for making http calls.'; this._controller.executeHandler = this._executeAll.bind(this); @@ -72,7 +72,7 @@ export class NotebookKernel { } } - private async _doExecution(cell: vscode.NotebookCell): Promise { + private async _doExecution(cell: vscode.NotebookCell, curl = false): Promise { const execution = this._controller.createNotebookCellExecution(cell); execution.executionOrder = ++this._executionOrder; const start = Date.now(); @@ -106,7 +106,7 @@ export class NotebookKernel { env: this.fileStateService.getEnv(filename), properties: DotHttpEditorView.getEnabledProperties(cell.document.fileName), target, - curl: false, + curl, contexts: contexts }) as DothttpExecuteResponse; const end = Date.now(); @@ -146,15 +146,22 @@ export class NotebookKernel { ]); execution.end(false, end); } else { - out.body = ""; - out.headers = {}; - const outs: Array = []; - const nativeContentTypes = this.parseAndAdd(out.response); - outs.push(vscode.NotebookCellOutputItem.json({ response: out, metadata: metadata }, Constants.NOTEBOOK_MIME_TYPE)); - outs.push(...nativeContentTypes); - execution.replaceOutput([ - new vscode.NotebookCellOutput(outs) - ]); + if (curl) { + execution.replaceOutput([ + new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.text(out.body, "text/x-shell")]) + ]); + } else { + out.body = ""; + out.headers = {}; + const outs: Array = []; + const nativeContentTypes = this.parseAndAdd(out.response); + outs.push(vscode.NotebookCellOutputItem.json({ response: out, metadata: metadata }, Constants.NOTEBOOK_MIME_TYPE)); + outs.push(...nativeContentTypes); + execution.replaceOutput([ + new vscode.NotebookCellOutput(outs) + ]); + } + execution.end(true, end) } } catch (error) { @@ -192,19 +199,42 @@ export class NotebookKernel { .map(key => mime.extension(response.headers![key])) .filter(key => key) .map(extension => { - const mimeType = mime.lookup(extension) - // this is a hack - // unless its called, it will not be available - // and its not customary to call this function - response.contentType = mimeType; - const ret = vscode.NotebookCellOutputItem.text(response.body, mimeType); - return ret; - + response.contentType = mime.lookup(extension); + return vscode.NotebookCellOutputItem.text(response.body, `text/x-${extension}`); }) } return []; } + async generateCurl(cell: vscode.NotebookCell) { + return this._doExecution(cell, true) + } + + async generateProgrammingLang(cell: vscode.NotebookCell) { + const execution = this._controller.createNotebookCellExecution(cell); + try { + execution.start(Date.now()); + const cellUri = cell.document.uri; + const cellNo = parseInt(cellUri.fragment.substring(2)); + const content = cell.document.getText(); + const target: string = await this._getTarget(cellUri, cellNo, content); + const langspec = await generateLangFromOptions({ content, filename: cell.document.fileName, target }); + if (langspec && langspec.code) { + execution.replaceOutput([ + new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.text(langspec.code as string, `text/x-${langspec.language}`)]) + ]); + } else { + execution.replaceOutput([ + new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.stderr("Failed to generate code, Probably syntax error")]) + ]); + } + } catch (error) { + execution.replaceOutput([ + new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.stderr(`Failed to generate code. error: ${error}`)]) + ]); + } + execution.end(true, Date.now()); + } } diff --git a/src/extension/views/editor.ts b/src/extension/views/editor.ts index 613b790..db854a0 100644 --- a/src/extension/views/editor.ts +++ b/src/extension/views/editor.ts @@ -6,7 +6,6 @@ import { DothttpRunOptions } from '../models/misc'; import { ApplicationServices } from '../services/global'; import { IHistoryService } from '../tingohelpers'; import querystring = require('querystring'); -var mime = require('mime-types'); export default class DotHttpEditorView implements vscode.TextDocumentContentProvider { diff --git a/src/extension/webextension.ts b/src/extension/webextension.ts index ba28e40..3030608 100644 --- a/src/extension/webextension.ts +++ b/src/extension/webextension.ts @@ -3,6 +3,7 @@ import { Constants } from './models/constants'; import { NotebookSerializer } from "./services/NotebookSerializer"; export async function activate(context: vscode.ExtensionContext) { + vscode.commands.executeCommand('setContext', Constants.EXTENSION_RUN_MODE, "web"); loadNoteBookControllerSafely(context); }