Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
j--wong committed Jan 1, 2017
0 parents commit a0c5037
Show file tree
Hide file tree
Showing 20 changed files with 415 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Tab indentation
[*]
indent_style = tab
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
[{.travis.yml,npm-shrinkwrap.json,package.json}]
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
out
node_modules
.vscode-test
*.vsix
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/src/**/*.js"
],
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/test/**/*.js"
],
"preLaunchTask": "npm"
}
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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
}
30 changes: 30 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isWatching": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/**
typings/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
vsc-extension-quickstart.md
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# JMESPath for Visual Studio Code

JMESPath (pronounced "james path") is a query language for JSON which allows one to extract and transform elements from a JSON document.

This extension lets you test JMESPath expressions from within Visual Studio Code.

For more information about JMESPath, please visit [here](http://jmespath.org)

## Features

This extension depends on the [JavaScript implementation of JMESPath](https://github.com/jmespath/jmespath.js) which is fully compliant with latest [specification](http://jmespath.org/specification.html).

![JMESPath Example](images/jmespath-example.gif)

## How to use this extension

This extension adds `JMESPath: Query JSON` command to the command palette.

To use the extension:

- Open a JSON document
- Run `JMESPath: Query JSON` command from command palette (`F1` on Windows or `Cmd+Shift+P` on Mac)
- Enter JMESPath expression
- Expression output will be shown in `JMESPath Output` window

## Release Notes

### 0.0.1

- Initial release


Binary file added images/jmespath-example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/jmespath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "vscode-jmespath",
"displayName": "JMESPath for VSCode",
"description": "Evaluate JMESPath queries within Visual Studio Code",
"version": "0.0.1",
"main": "./out/src/jmespathMain",
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/sinon": "^1.16.34",
"chai": "^3.5.0",
"sinon": "^1.17.7",
"tslint": "^4.2.0",
"typescript": "^2.1.4",
"vscode": "^0.11.0"
},
"dependencies": {
"jmespath": "^0.15.0"
},
"repository": {
"type": "git",
"url": "https://github.com/j--wong/vscode-jmespath.git"
},
"publisher": "joshwong",
"icon": "images/jemspath.png",
"galleryBanner": {
"color": "#13254a",
"theme": "dark"
},
"private": true,
"engines": {
"vscode": "^1.0.0"
},
"categories": [
"Other"
],
"keywords": [
"jmespath",
"json",
"query"
],
"activationEvents": [
"onLanguage:json",
"onCommand:jmespath.query"
],
"contributes": {
"commands": [
{
"title": "JMESPath: Query JSON",
"command": "jmespath.query"
}
],
"configuration": {
"title": "",
"properties": {
"jmespath.rememberRecentExpressions": {
"type": "boolean",
"default": true,
"description": "Specify whether or not to record recently entered expressions"
},
"jmespath.maxRecentExpressionsToRemember": {
"type": "integer",
"default": 25,
"description": "Specify the number of expressions to remember"
}
}
}
}
}
14 changes: 14 additions & 0 deletions src/jmespathMain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

import * as vscode from "vscode";
import { queryJson } from "./jmespathQuery";

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerTextEditorCommand("jmespath.query",
(textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => {
queryJson(context);
}
)
);
}
45 changes: 45 additions & 0 deletions src/jmespathQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as vscode from "vscode";
let jmespath = require("jmespath");

let outputChannel = vscode.window.createOutputChannel("JMESPath Output");

export function queryJson(context: vscode.ExtensionContext) {
let editor = vscode.window.activeTextEditor;

if (editor.document.languageId !== "json") {
vscode.window.showInformationMessage("Please open a JSON document.");
return;
}

let options: vscode.InputBoxOptions = {
prompt: "Enter JMESPath expression",
placeHolder: "JMESPath expression"
};

vscode.window.showInputBox(options).then((expression) => {
if (expression.trim().length === 0) {
return;
}

try {
jmespath.compile(expression);
}
catch (e) {
vscode.window.showErrorMessage(`${e.message}`);
return;
}

let data = vscode.window.activeTextEditor.document.getText();
try {
let jsonData = JSON.parse(data);
let searchResult = jmespath.search(jsonData, expression);

outputChannel.clear();
outputChannel.append(JSON.stringify(searchResult, null, " "));
outputChannel.show();
} catch (e) {
vscode.window.showErrorMessage(`${e.message}`);
return;
}
});
}
22 changes: 22 additions & 0 deletions src/util/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as path from "path";
import * as vscode from "vscode";

export default class Environment {
private context: vscode.ExtensionContext;

constructor(context: vscode.ExtensionContext) {
this.context = context;
}

public getHomeDir(): string {
return process.env[(process.platform === "win32") ? "USERPROFILE" : "HOME"];
}

public isInsiders(): boolean {
return /insiders/.test(this.context.asAbsolutePath(""));
}

public getExtensionDir(): string {
return path.join(this.getHomeDir(), this.isInsiders() ? ".vscode-insiders" : ".vscode", "extensions");
}
}
8 changes: 8 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let testRunner = require("vscode/lib/testrunner");

testRunner.configure({
ui: "bdd",
useColors: true
});

module.exports = testRunner;
44 changes: 44 additions & 0 deletions test/jmespathMain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as vscode from "vscode";
import * as jmespathMain from "../src/jmespathMain";
import * as assert from "assert";
import * as sinon from "sinon";
import chai = require("chai");

let expect = chai.expect;

describe("JMESPath extension", () => {
let extensionId = "joshwong.vscode-jmespath";

describe("#activate()", () => {
let context: vscode.ExtensionContext;
let stubTextEditorCommand: sinon.SinonStub;

beforeEach(() => {
context = {
subscriptions: [],
workspaceState: null,
globalState: null,
extensionPath: null,
asAbsolutePath: sinon.stub()
};
stubTextEditorCommand = sinon.stub(vscode.commands, "registerTextEditorCommand");
});

afterEach(() => {
stubTextEditorCommand.restore();
});

it("should register 'jmespath.query' command", sinon.test(() => {
jmespathMain.activate(context);
expect(stubTextEditorCommand.calledWith("jmespath.query")).to.be.true;
}));

it("should add disposable command to subscriptions array", sinon.test(() => {
jmespathMain.activate(context);

expect(context.subscriptions).to.not.be.empty;
expect(context.subscriptions.length).to.equals(1);
}));
});

});
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "out",
"noLib": true,
"sourceMap": true,
"rootDir": ".",
"moduleResolution": "node"
},
"exclude": [
"node_modules",
".vscode-test"
]
}
Loading

0 comments on commit a0c5037

Please sign in to comment.