-```
-
-### `rneAvatarBadge`
-
-#### Avatar with Badge Component
-
-```javascript
-
-
-
-
-```
-
-### `rneBadge`
-
-#### Badge Component
-
-```javascript
-
-```
-
-### `rneBadgeMini`
-
-#### Mini Badge Component
-
-```javascript
-
-```
-
-### `rneBottomSheet`
-
-#### Bottom Sheet Component
-
-```javascript
-
- $0
-
-```
-
-### `rneButton`
-
-#### Simple Button Component
-
-```javascript
-
-```
-
-### `rneButtonGroup`
-
-#### Button Group Component
-
-```javascript
-
-```
-
-### `rneButtonIcon`
-
-#### Button with Icon Component
-
-```javascript
-
-```
-
-### `rneButtonType`
-
-#### Button with types Component
-
-```javascript
-
-```
-
-### `rneCard`
-
-#### Basic Card Component
-
-```javascript
-
- $1
- ${2:
- }
-
- ${4:
-
- $5
-
- }
- $6
-
-
-```
-
-### `rneCheckBox`
-
-#### CheckBox Component
-
-```javascript
-
-```
-
-### `rneChip`
-
-#### Simple Chip Component
-
-```javascript
-
-```
-
-### `rneChipIcon`
-
-#### Chip with Icon Component
-
-```javascript
-
-```
-
-### `rneDivider`
-
-#### Divider Component
-
-```javascript
-
-```
-
-### `rneFAB`
-
-#### Floating Action Button Component
-
-```javascript
-
-```
-
-### `rneIcon`
-
-#### Icon Component
-
-```javascript
-
-```
-
-### `rneImage`
-
-#### Image Component
-
-```javascript
-
-```
-
-### `rneLinearProgress`
-
-#### Linear Progress Component
-
-```javascript
-
-```
-
-### `rneLinearProgressIndeterminate`
-
-#### Linear Progress indeterminate variant Component
-
-```javascript
-
-```
-
-### `rneRadio`
-
-#### CheckBox Component
-
-```javascript
-
-```
-
-### `rneSearchBar`
-
-#### Search Bar Component
-
-```javascript
-
-```
-
-### `rneSlider`
-
-#### Slider Component
-
-```javascript
-
-```
-
-### `rneSpeedDial`
-
-#### Speed Dial Wrapper Component
-
-```javascript
-
- $0
-
-```
-
-### `rneSpeedDialAction`
-
-#### Speed Dial Action Component
-
-```javascript
-
-```
-
-### `rneText`
-
-#### Text Component
-
-```javascript
-
- $0
-
-```
-
-### `rneuCircularSlider`
-
-#### Universal Circular Slider Component
-
-```javascript
-
-```
-
-
+
+
+
+
+
+
+
+ Cross Platform React Native UI Toolkit
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+![React Native Elements UI Toolkit](https://user-images.githubusercontent.com/5962998/37248832-a7060286-24b1-11e8-94a8-847ab6ded4ec.png)
diff --git a/src/extension.ts b/src/extension.ts
index cb3c066..3e22fad 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -1,7 +1,6 @@
import * as vscode from "vscode";
import loadSnippets from "./snippets";
import getExistingImports from "./getExistingImports";
-import { getSnippetImports } from "./utils";
class RNECompletionItem extends vscode.CompletionItem {
imports: string[] | undefined;
}
@@ -21,7 +20,7 @@ export async function activate(
);
}
- const snippets = await loadSnippets();
+ const snippets = loadSnippets();
function getAdditionalTextEdits({
imports,
@@ -34,13 +33,12 @@ export async function activate(
let existingImports: Set | null;
let insertPosition: vscode.Position = new vscode.Position(0, 0);
let coreInsertPosition: vscode.Position | null = null;
- let universeInsertPosition: vscode.Position | null = null;
try {
({
existingImports,
insertPosition,
coreInsertPosition,
- universeInsertPosition,
+ // universeInsertPosition,
} = getExistingImports(document));
} catch (error) {
existingImports = null;
@@ -50,15 +48,8 @@ export async function activate(
const finalExistingImports = existingImports;
if (finalExistingImports) {
const coreImports = imports.filter(
- (comp: string) =>
- !comp.endsWith("Universe") && !finalExistingImports.has(comp)
+ (comp: string) => !finalExistingImports.has(comp)
);
- const universeImports = imports
- .filter(
- (comp: string) =>
- comp.endsWith("Universe") && !finalExistingImports.has(comp)
- )
- .map((comp: string) => `${comp.replace("Universe", "")} as ${comp}`);
if (coreImports.length) {
if (coreInsertPosition) {
additionalTextEdits.push(
@@ -78,31 +69,12 @@ export async function activate(
);
}
}
- if (universeImports.length) {
- if (universeInsertPosition) {
- additionalTextEdits.push(
- vscode.TextEdit.insert(
- universeInsertPosition,
- ", " + universeImports.join(", ")
- )
- );
- } else {
- additionalTextEdits.push(
- vscode.TextEdit.insert(
- insertPosition,
- `import { ${universeImports.join(
- ", "
- )} } from 'react-native-elements-universe'\n`
- )
- );
- }
- }
}
return additionalTextEdits;
}
for (const snippet of Object.values(snippets)) {
- const { prefix, description } = snippet;
+ const { prefix, description, imports } = snippet;
context.subscriptions.push(
vscode.commands.registerCommand(`extension.${prefix}`, async () =>
vscode.window.withProgress(
@@ -118,15 +90,14 @@ export async function activate(
}>,
token: vscode.CancellationToken
) => {
- const body = (typeof snippet.body === "function"
- ? snippet.body()
- : snippet.body
+ const body = (
+ typeof snippet.body === "function" ? snippet.body() : snippet.body
).replace(/^\n|\n$/gm, "");
if (token.isCancellationRequested) return;
const additionalTextEdits = getAdditionalTextEdits({
- imports: getSnippetImports(body),
+ imports: imports,
});
if (token.isCancellationRequested) return;
@@ -151,11 +122,10 @@ export async function activate(
const getCompletionItems = ((): RNECompletionItem[] => {
const result = [];
for (const snippet of Object.values(snippets)) {
- const { prefix, description, docKey, previewURL } = snippet;
+ const { prefix, description, docKey, previewURL, imports } = snippet;
- const body = (typeof snippet.body === "function"
- ? snippet.body?.()
- : snippet.body
+ const body = (
+ typeof snippet.body === "function" ? snippet.body?.() : snippet.body
).replace(/^\n|\n$/gm, "");
let extendedDoc = `**${description.trim()}**`;
@@ -171,7 +141,7 @@ export async function activate(
const completion = new RNECompletionItem(prefix);
completion.insertText = new vscode.SnippetString(body);
completion.documentation = new vscode.MarkdownString(extendedDoc);
- completion.imports = getSnippetImports(body);
+ completion.imports = imports;
result.push(completion);
}
return result;
diff --git a/src/getExistingImports.ts b/src/getExistingImports.ts
index ec883dc..70a67c4 100644
--- a/src/getExistingImports.ts
+++ b/src/getExistingImports.ts
@@ -2,13 +2,11 @@ import * as vscode from "vscode";
import jscodeshift, { ImportDeclaration, ASTPath } from "jscodeshift";
import chooseJSCodeshiftParser from "jscodeshift-choose-parser";
-export default function getExistingImports(
- document: vscode.TextDocument
-): {
+export default function getExistingImports(document: vscode.TextDocument): {
existingImports: Set;
insertPosition: vscode.Position;
coreInsertPosition: vscode.Position | null;
- universeInsertPosition: vscode.Position | null;
+ // universeInsertPosition: vscode.Position | null;
} {
const text = document.getText();
const parser = chooseJSCodeshiftParser(document.uri.fsPath);
@@ -18,7 +16,7 @@ export default function getExistingImports(
let insertLine = 0;
let coreInsertPosition: vscode.Position | null = null;
- let universeInsertPosition: vscode.Position | null = null;
+ // let universeInsertPosition: vscode.Position | null = null;
let root;
try {
@@ -49,25 +47,26 @@ export default function getExistingImports(
result.add(local.name);
}
}
- } else if (source === "react-native-elements-universe") {
- for (const specifier of node?.specifiers) {
- if (specifier.type !== "ImportSpecifier") continue;
- const { loc } = specifier;
- if (loc) {
- const { line, column } = loc.end;
- universeInsertPosition = new vscode.Position(line - 1, column);
- }
- const { imported, local } = specifier;
- if (imported && local && imported.name + "Universe" === local.name) {
- result.add(local.name);
- }
- }
}
+ // else if (source === "react-native-elements-universe") {
+ // for (const specifier of node?.specifiers) {
+ // if (specifier.type !== "ImportSpecifier") continue;
+ // const { loc } = specifier;
+ // if (loc) {
+ // const { line, column } = loc.end;
+ // universeInsertPosition = new vscode.Position(line - 1, column);
+ // }
+ // const { imported, local } = specifier;
+ // if (imported && local && imported.name + "Universe" === local.name) {
+ // result.add(local.name);
+ // }
+ // }
+ // }
});
return {
existingImports: result,
insertPosition: new vscode.Position(insertLine, 0),
coreInsertPosition,
- universeInsertPosition,
+ // universeInsertPosition,
};
}
diff --git a/src/snip.ts b/src/snip.ts
deleted file mode 100644
index 93e762a..0000000
--- a/src/snip.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-import { CompiledSnippet } from "./types";
-
-export default function snip(
- strings: TemplateStringsArray,
- ...expressions: any[]
-): CompiledSnippet {
- const parts = [];
- for (let i = 0; i < strings.length - 1; i++) {
- parts.push(strings[i]);
- parts.push(
- Array.isArray(expressions[i])
- ? `|${expressions[i].join(",")}|`
- : String(expressions[i])
- );
- }
- parts.push(...strings.slice(expressions.length));
- const body = parts.join("").replace(/\s+$/gm, "");
-
- const makeSnippet = (): string => {
- let lastIndex = 0;
- const parts = [];
- const ifRx = /^\s*\{\{\s*#if\s*(\S+)\s*(===\s*(\S+)\s*)\}\}([^\n]*\n)?/gm;
- const endifRx = /^\s*\{\{\s*\/if\s*\}\}([^\n]*\n)?/gm;
- let start, end;
- while ((start = ifRx.exec(body))) {
- endifRx.lastIndex = start.index + start[0].length;
- if ((end = endifRx.exec(body))) {
- let value;
- try {
- value = start[3] ? JSON.parse(start[3]) : true;
- } catch (error) {
- throw new Error(`value is not JSON: ${start[3]}`);
- }
- parts.push(body.substring(lastIndex, start.index));
- // if (options[parameter] === value) {
- // parts.push(body.substring(start.index + start[0].length, end.index));
- // }
- lastIndex = end.index + end[0].length;
- }
- }
- parts.push(body.substring(lastIndex));
-
- let counter = 0;
- return parts
- .join("")
- .replace(/^\n|\n$/g, "")
- .replace(/#/g, () => String(++counter));
- };
- return makeSnippet;
-}
diff --git a/src/snippets.ts b/src/snippets.ts
index 3f48336..3fdbd4d 100644
--- a/src/snippets.ts
+++ b/src/snippets.ts
@@ -1,10 +1,10 @@
import Components from "./components";
import { Snippet } from "./types";
-export default async function loadSnippets(): Promise> {
+export default function loadSnippets(): Record {
const result = {};
Components.map((file) => {
- const { prefix, description, body, docKey } = file;
+ const { prefix, description, body, docKey, imports } = file;
if (!prefix || typeof prefix !== "string") {
throw new Error(
`src/components/${prefix}: prefix must be a string if exported`
@@ -26,7 +26,8 @@ export default async function loadSnippets(): Promise> {
body,
docKey,
previewURL: prefix,
+ imports: imports,
};
});
- return Promise.resolve(result);
+ return result;
}
diff --git a/src/types.ts b/src/types.ts
index 1527de8..2b6a004 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -14,5 +14,6 @@ export type Snippet = {
description: string;
body: SnippetBody;
docKey?: string;
+ imports?: string[];
previewURL?: string;
};