Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

els-component-extraction-addon

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

els-component-extraction-addon - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

71

index.js
"use strict";
const { TextEdit, Position } = require('vscode-languageserver');
const { URI } = require('vscode-uri');
const { TextEdit, Position, Command } = require("vscode-languageserver");
const { URI } = require("vscode-uri");

@@ -10,3 +10,3 @@ function normalizeToAngleBracketComponent(name) {

if (name.includes('.')) {
if (name.includes(".")) {
return name;

@@ -16,4 +16,4 @@ }

return name.replace(SIMPLE_DASHERIZE_REGEXP, (char, index) => {
if (char === '/') {
return '::';
if (char === "/") {
return "::";
}

@@ -26,3 +26,3 @@

// Remove all occurrences of '-'s from the name that aren't starting with `-`
return char === '-' ? '' : char.toLowerCase();
return char === "-" ? "" : char.toLowerCase();
});

@@ -33,7 +33,11 @@ }

onInit(_, project) {
if (!('els.executeInEmberCLI' in project.executors)) {
if (!("els.executeInEmberCLI" in project.executors)) {
console.error('Unable to find "ember-fast-cli" addon.');
return;
}
project.executors['els.extractSourceCodeToComponent'] = async (server, filePath, [componentName, { range, source, uri }]) => {
project.executors["els.extractSourceCodeToComponent"] = async (
server,
filePath,
[componentName, { range, source, uri }]
) => {
try {

@@ -43,4 +47,4 @@ // const ast = server.templateCompletionProvider.getAST(document.getText(range));

await server.onExecute({
command: 'els.executeInEmberCLI',
arguments: [filePath, `g component ${componentName}`]
command: "els.executeInEmberCLI",
arguments: [filePath, `g component ${componentName}`],
});

@@ -51,8 +55,16 @@ // going to wait for file changes api

if (!(componentName in registry.component)) {
console.log(`Unable to find component ${componentName} in registry ${JSON.stringify(Object.keys(registry.component))}`);
console.log(
`Unable to find component ${componentName} in registry ${JSON.stringify(
Object.keys(registry.component)
)}`
);
return;
}
const fileName = registry['component'][componentName].find((file) => file.endsWith('.hbs'));
const fileName = registry["component"][componentName].find((file) =>
file.endsWith(".hbs")
);
if (!fileName) {
console.log(`Unable to find template file for component ${componentName}`);
console.log(
`Unable to find template file for component ${componentName}`
);
return;

@@ -63,5 +75,10 @@ }

changes: {
[uri]: [TextEdit.replace(range, `<${normalizeToAngleBracketComponent(componentName)} />`)],
[fileUri]: [TextEdit.insert(Position.create(0, 0), source)]
}
[uri]: [
TextEdit.replace(
range,
`<${normalizeToAngleBracketComponent(componentName)} />`
),
],
[fileUri]: [TextEdit.insert(Position.create(0, 0), source)],
},
};

@@ -73,3 +90,23 @@ await server.connection.workspace.applyEdit(edit);

};
}
},
onCodeAction(_, params) {
if (!params.textDocument.uri.endsWith(".hbs")) {
return;
}
const act = Command.create(
"Extract selection to component",
"els.getUserInput",
{
placeHolder: "Enter component name",
},
"els.extractSourceCodeToComponent",
{
source: focusPath.sourceForNode(),
range,
uri: params.textDocument.uri,
}
);
return [act];
},
};
{
"name": "els-component-extraction-addon",
"version": "0.1.3",
"version": "0.1.4",
"description": "Ember Language Server Templates Code Actions extension",

@@ -25,3 +25,6 @@ "main": "index.js",

"ember-language-server": {
"entry": "./index"
"entry": "./index",
"capabilities": {
"codeActionProvider": true
}
},

@@ -28,0 +31,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc