Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn"
}
}
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn"
}
}
22 changes: 22 additions & 0 deletions .github/workflows/datadog-synthetics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Datadog Synthetics CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
synthetics-ci:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run Datadog Synthetics tests
uses: datadog/synthetics-ci-github-action@v0.1.0
with:
api_key: ${{ secrets.DATADOG_API_KEY }}
app_key: ${{ secrets.DATADOG_APP_KEY }}
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

### Bug Fixes

- **syntax:** avoid generating import statements when selecting text which is not a valid variable name
- **syntax:** avoid generating import statements when selecting text which is
not a valid variable name

### Improvements

Expand All @@ -54,7 +55,8 @@

### Bug Fixes

- **syntax:** avoid generating import statements when selecting text which contains "\n"
- **syntax:** avoid generating import statements when selecting text which
contains "\n"

### Improvements

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Python Path

This extension adds a set of tools which help you generate internal import statements in a python project.
This extension adds a set of tools which help you generate internal import
statements in a python project.

## Features

Expand All @@ -19,8 +20,8 @@ Copies the full module name of the current file to the clipboard.

### Generate import statement

Copies an import statement for the selected text to the clipboard.
In case of a simple selection, the generated statement will be:
Copies an import statement for the selected text to the clipboard. In case of a
simple selection, the generated statement will be:

```
from module.name import selected_text
Expand All @@ -41,7 +42,8 @@ from module.name import (

## Miscellaneous

Inspiration from the Sublime Package: https://github.com/pokidovea/copy_python_path
Inspiration from the Sublime Package:
https://github.com/pokidovea/copy_python_path

## Credits

Expand Down
15 changes: 7 additions & 8 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ function getPythonPath(filePath) {
const fileName = splittedPath.pop();

// removing extension
let pythonPath =
fileName !== "__init__.py"
? [fileName.substring(0, fileName.lastIndexOf("."))]
: [];
let pythonPath = fileName !== "__init__.py"
? [fileName.substring(0, fileName.lastIndexOf("."))]
: [];

while (
splittedPath.length > 0 &&
Expand All @@ -36,8 +35,8 @@ function copyPythonPath(uri) {
: vscode.window.activeTextEditor.document.fileName;
const pythonPath = getPythonPath(filePath);
const selections = vscode.window.activeTextEditor.selections
.map(s => vscode.window.activeTextEditor.document.getText(s))
.filter(s => !!s && !s.includes("\n") && !s.trim().includes(" "));
.map((s) => vscode.window.activeTextEditor.document.getText(s))
.filter((s) => !!s && !s.includes("\n") && !s.trim().includes(" "));
if (pythonPath && selections.length > 0) {
const importStatement = generateImportStatement(pythonPath, selections);
vscode.env.clipboard.writeText(importStatement);
Expand All @@ -57,14 +56,14 @@ function generateImportStatement(pythonPath, selections) {
const selection = selections[0].trim();
return `from ${pythonPath} import ${selection}`;
}
const selection = selections.map(s => `\t${s.trim()},`).join("\n");
const selection = selections.map((s) => `\t${s.trim()},`).join("\n");
return `from ${pythonPath} import (\n${selection}\n)`;
}

function activate(context) {
let disposable = vscode.commands.registerCommand(
"extension.copyPythonPath",
copyPythonPath
copyPythonPath,
);
context.subscriptions.push(disposable);
}
Expand Down
17 changes: 8 additions & 9 deletions test/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
//

// The module 'assert' provides assertion methods from node
const assert = require('assert');
const assert = require("assert");

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
// const vscode = require('vscode');
// const myExtension = require('../extension');

// Defines a Mocha test suite to group tests of similar kind together
suite("Extension Tests", function() {

// Defines a Mocha unit test
test("Something 1", function() {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
suite("Extension Tests", function () {
// Defines a Mocha unit test
test("Something 1", function () {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.

const testRunner = require('vscode/lib/testrunner');
const testRunner = require("vscode/lib/testrunner");

// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.)
useColors: true // colored output from test results
ui: "tdd", // the TDD UI is being used in extension.test.js (suite, test, etc.)
useColors: true, // colored output from test results
});

module.exports = testRunner;
module.exports = testRunner;
59 changes: 37 additions & 22 deletions vsc-extension-quickstart.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
# Welcome to your VS Code Extension

## What's in the folder
* This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your extension and command.
The sample plugin registers a command and defines its title and command name. With this information
VS Code can show the command in the command palette. It doesn鈥檛 yet need to load the plugin.
* `extension.js` - this is the main file where you will provide the implementation of your command.
The file exports one function, `activate`, which is called the very first time your extension is
activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
We pass the function containing the implementation of the command as the second parameter to
`registerCommand`.

- This folder contains all of the files necessary for your extension.
- `package.json` - this is the manifest file in which you declare your extension
and command. The sample plugin registers a command and defines its title and
command name. With this information VS Code can show the command in the
command palette. It doesn鈥檛 yet need to load the plugin.
- `extension.js` - this is the main file where you will provide the
implementation of your command. The file exports one function, `activate`,
which is called the very first time your extension is activated (in this case
by executing the command). Inside the `activate` function we call
`registerCommand`. We pass the function containing the implementation of the
command as the second parameter to `registerCommand`.

## Get up and running straight away
* Press `F5` to open a new window with your extension loaded.
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
* Set breakpoints in your code inside `extension.js` to debug your extension.
* Find output from your extension in the debug console.

- Press `F5` to open a new window with your extension loaded.
- Run your command from the command palette by pressing (`Ctrl+Shift+P` or
`Cmd+Shift+P` on Mac) and typing `Hello World`.
- Set breakpoints in your code inside `extension.js` to debug your extension.
- Find output from your extension in the debug console.

## Make changes
* You can relaunch the extension from the debug toolbar after changing code in `extension.js`.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.

- You can relaunch the extension from the debug toolbar after changing code in
`extension.js`.
- You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your
extension to load your changes.

## Explore the API
* You can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`.

- You can open the full set of our API when you open the file
`node_modules/vscode/vscode.d.ts`.

## Run tests
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`.
* Press `F5` to run the tests in a new window with your extension loaded.
* See the output of the test result in the debug console.
* Make changes to `test/extension.test.js` or create new test files inside the `test` folder.
* By convention, the test runner will only consider files matching the name pattern `**.test.js`.
* You can create folders inside the `test` folder to structure your tests any way you want.

- Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the
launch configuration dropdown pick `Launch Tests`.
- Press `F5` to run the tests in a new window with your extension loaded.
- See the output of the test result in the debug console.
- Make changes to `test/extension.test.js` or create new test files inside the
`test` folder.
- By convention, the test runner will only consider files matching the name
pattern `**.test.js`.
- You can create folders inside the `test` folder to structure your tests any
way you want.