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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "error",
"func-style": ["error", "expression"],
"arrow-body-style": ["error", "as-needed"],
"import/no-extraneous-dependencies": "error"
}
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"lint-staged": {
"./{src,test}/**/*.{ts,js}": [
"eslint -c .eslintrc.json --fix"
],
"packages/*/src/**/*.{ts,js}": [
"eslint -c .eslintrc.json --fix"
],
"packages/*/test/**/*.{ts,js}": [
"eslint -c .eslintrc.json --fix"
]
},
"private": true,
Expand Down
16 changes: 6 additions & 10 deletions packages/aura-language-server/src/__tests__/aura-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ import { TextDocument, Position } from 'vscode-languageserver';
import { getAuraBindingValue, parse } from '../aura-utils';

describe('getAuraBindingValue', () => {
function createDocument(content: string): TextDocument {
return TextDocument.create('file:///test.cmp', 'html', 0, content);
}
const createDocument = (content: string): TextDocument => TextDocument.create('file:///test.cmp', 'html', 0, content);

function createPosition(line: number, character: number): Position {
return Position.create(line, character);
}
const createPosition = (line: number, character: number): Position => Position.create(line, character);

function getBindingValue(content: string, line: number, character: number): string | null {
const getBindingValue = (content: string, line: number, character: number): string | null => {
const document = createDocument(content);
const htmlDocument = parse(content);
const position = createPosition(line, character);
console.log('position', position);
return getAuraBindingValue(document, position, htmlDocument);
}
};

// simple function to find the cursor position in a string, helpful for readability
function findCursorPosition(content: string): number {
const findCursorPosition = (content: string): number => {
const cursorPosition = content.indexOf('|');
return cursorPosition;
}
};

describe('basic functionality', () => {
it('should extract property from v binding in attribute', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import glob from 'glob';

const checkedPackagePatterns: RegExp[] = [/^@salesforce/i, /^@lwc/i];

function readJsonFile(jsonFilePath: string): any {
const readJsonFile = (jsonFilePath: string): any => {
try {
return JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'));
} catch (e) {
throw new Error(`Error reading json file from ${jsonFilePath}: ${e}`);
}
}
};

const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
const packageJson = readJsonFile(packageJsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const normalize = (start: string, p: string): string => {
return p;
};

const uriToFile = (uri: string): string => {
return URI.parse(uri).fsPath;
};
const uriToFile = (uri: string): string => URI.parse(uri).fsPath;

describe('indexer parsing content', () => {
afterEach(() => {
Expand Down
4 changes: 1 addition & 3 deletions packages/aura-language-server/src/aura-indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ export default class AuraIndexer implements Indexer {
const tagObj = auraStandard[tag];
const info = new TagInfo(null, 'STANDARD', false, []);
if (tagObj.attributes) {
tagObj.attributes.sort((a, b) => {
return a.name.localeCompare(b.name);
});
tagObj.attributes.sort((a, b) => a.name.localeCompare(b.name));
for (const a of tagObj.attributes) {
// TODO - could we use more in depth doc from component library here?
info.attributes.push(new AttributeInfo(a.name, a.description, undefined, undefined, a.type, undefined, 'Aura Attribute'));
Expand Down
12 changes: 3 additions & 9 deletions packages/aura-language-server/src/aura-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ const RESOURCES_DIR = 'resources';
*/
const AURA_EXPRESSION_REGEX = /['"]?\s*{[!#]\s*[!]?[vmc]\.(\w*)(\.?\w*)*\s*}\s*['"]?/;

export const getAuraStandardResourcePath = (): string => {
return join(__dirname, RESOURCES_DIR, AURA_STANDARD);
};
export const getAuraStandardResourcePath = (): string => join(__dirname, RESOURCES_DIR, AURA_STANDARD);

export const getAuraSystemResourcePath = (): string => {
return join(__dirname, RESOURCES_DIR, AURA_SYSTEM);
};
export const getAuraSystemResourcePath = (): string => join(__dirname, RESOURCES_DIR, AURA_SYSTEM);

// Create a parse function that works with the new API
export const parse = (input: string): HTMLDocument => {
Expand All @@ -72,9 +68,7 @@ const stripQuotes = (str: string | null): string | null => {
return str;
};

const hasQuotes = (str: string): boolean => {
return (str.at(0) === '"' && str.at(-1) === '"') || (str.at(0) === "'" && str.at(-1) === "'");
};
const hasQuotes = (str: string): boolean => (str.at(0) === '"' && str.at(-1) === '"') || (str.at(0) === "'" && str.at(-1) === "'");

const getTagNameRange = (document: TextDocument, offset: number, tokenType: TokenType, startOffset: number): Range | null => {
const scanner = createScanner(document.getText(), startOffset);
Expand Down
44 changes: 20 additions & 24 deletions packages/aura-language-server/src/markup/auraTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ import { IAttributeData, IHTMLDataProvider, IValueData } from 'vscode-html-langu

let indexer: AuraIndexer;

function getAuraTags(): Map<string, TagInfo> {
const getAuraTags = (): Map<string, TagInfo> => {
if (indexer) {
return indexer.getAuraTags();
}
return new Map();
}
function getAuraByTag(tag: string): TagInfo {
};

const getAuraByTag = (tag: string): TagInfo => {
if (indexer) {
return indexer.getAuraByTag(tag);
}
return undefined;
}
};

export function setIndexer(idx: AuraIndexer): void {
export const setIndexer = (idx: AuraIndexer): void => {
indexer = idx;
}
};

function getTagsData(): { name: string; description?: string; attributes: IAttributeData[] }[] {
return Array.from(getAuraTags()).map(([tag, tagInfo]) => ({
const getTagsData = (): { name: string; description?: string; attributes: IAttributeData[] }[] =>
Array.from(getAuraTags()).map(([tag, tagInfo]) => ({
name: tag,
description: tagInfo.getHover(),
attributes: tagInfo.attributes.map((attr) => ({
Expand All @@ -31,9 +32,8 @@ function getTagsData(): { name: string; description?: string; attributes: IAttri
valueSet: attr.type,
})),
}));
}

function getAttributesData(tag: string): IAttributeData[] {
const getAttributesData = (tag: string): IAttributeData[] => {
const cTag = getAuraByTag(tag);
if (cTag) {
return cTag.attributes.map((attr) => ({
Expand All @@ -43,20 +43,16 @@ function getAttributesData(tag: string): IAttributeData[] {
}));
}
return [];
}
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getValuesData(tag: string, attribute: string): IValueData[] {
const getValuesData = (tag: string, attribute: string): IValueData[] =>
// TODO provide suggestions by consulting shapeService
return [];
}

export function getAuraTagProvider(): IHTMLDataProvider {
return {
getId: (): string => 'aura',
isApplicable: (languageId): boolean => languageId === 'html',
provideTags: getTagsData,
provideAttributes: getAttributesData,
provideValues: getValuesData,
};
}
[];
export const getAuraTagProvider = (): IHTMLDataProvider => ({
getId: (): string => 'aura',
isApplicable: (languageId): boolean => languageId === 'html',
provideTags: getTagsData,
provideAttributes: getAttributesData,
provideValues: getValuesData,
});
22 changes: 12 additions & 10 deletions packages/aura-language-server/src/tern-server/string-util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function isAlphaNumberic(code: number): boolean {
const isAlphaNumberic = (code: number): boolean => {
if (code > 47 && code < 58) {
// numeric
return true;
Expand All @@ -12,9 +12,9 @@ function isAlphaNumberic(code: number): boolean {
return true;
}
return false;
}
};

export function findWord(str: string, offset: number): { start: number; end: number } {
export const findWord = (str: string, offset: number): { start: number; end: number } => {
let start = -1;
let end = -1;

Expand Down Expand Up @@ -55,8 +55,9 @@ export function findWord(str: string, offset: number): { start: number; end: num
end,
};
}
}
export function countPreviousCommas(str: string, offset: number): number {
};

export const countPreviousCommas = (str: string, offset: number): number => {
let commas = 0;
let pos: number = offset;
let c: number;
Expand All @@ -72,8 +73,9 @@ export function countPreviousCommas(str: string, offset: number): number {
--pos;
}
return commas;
}
export function findPreviousLeftParan(str: string, offset: number): number {
};

export const findPreviousLeftParan = (str: string, offset: number): number => {
let start = -1;
let pos: number = offset;
let c: number;
Expand All @@ -89,9 +91,9 @@ export function findPreviousLeftParan(str: string, offset: number): number {
--pos;
}
return start;
}
};

export function findPreviousWord(str: string, offset: number): { start: number; end: number } {
export const findPreviousWord = (str: string, offset: number): { start: number; end: number } => {
let start = -1;
let end = -1;

Expand Down Expand Up @@ -142,4 +144,4 @@ export function findPreviousWord(str: string, offset: number): { start: number;
if (start > -1 && end > -1) {
return { start, end: end - boundaryOffset };
}
}
};
Loading
Loading