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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import mockFs from 'mock-fs';
import URI from 'vscode-uri';

function normalize(start: string, p: string): string {
const normalize = (start: string, p: string): string => {
// Fix relative paths on windows
if (start.indexOf('\\') !== -1) {
start = start.replace(/\\/g, '/');
Expand All @@ -18,10 +18,11 @@ function normalize(start: string, p: string): string {
return p.slice(start.length + 1);
}
return p;
}
function uriToFile(uri: string): string {
};

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

describe('indexer parsing content', () => {
afterEach(() => {
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('indexer parsing content', () => {
expect(tagInfo).toBeObject();
expect(tagInfo.name).toEqual('c:wireLdsCmp');
expect(tagInfo.file).toEndWith('wireLdsCmp.cmp');
expect(tagInfo.type).toEqual(2);
expect(tagInfo.type).toEqual('CUSTOM');
expect(tagInfo.lwc).toEqual(false);
expect(tagInfo.location).toBeObject();
expect(tagInfo.location.uri).toEndWith('wireLdsCmp.cmp');
Expand Down
13 changes: 5 additions & 8 deletions packages/aura-language-server/src/aura-indexer/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { shared, Indexer, TagInfo, utils, AttributeInfo } from '@salesforce/lightning-lsp-common';
import { Indexer, TagInfo, utils, AttributeInfo } from '@salesforce/lightning-lsp-common';
import { componentFromFile, componentFromDirectory } from '../util/component-util';
import { Location } from 'vscode-languageserver';
import * as auraUtils from '../aura-utils';
import * as fs from 'fs';
import LineColumnFinder from 'line-column';
import URI from 'vscode-uri';
import EventsEmitter from 'events';
import { TagType } from '@salesforce/lightning-lsp-common/lib/indexer/tagInfo';
import { parse } from '../aura-utils';
import { Node } from 'vscode-html-languageservice';
import { AuraWorkspaceContext } from '../context/aura-context';

const { WorkspaceType } = shared;

export default class AuraIndexer implements Indexer {
public readonly eventEmitter = new EventsEmitter();

Expand Down Expand Up @@ -126,7 +123,7 @@ export default class AuraIndexer implements Indexer {

for (const file of markupfiles) {
try {
await this.indexFile(file, this.context.type === WorkspaceType.SFDX);
await this.indexFile(file, this.context.type === 'SFDX');
} catch (e) {
console.log(`Error parsing markup from ${file}:`, e);
}
Expand Down Expand Up @@ -170,7 +167,7 @@ export default class AuraIndexer implements Indexer {
for (const tag in auraSystem) {
if (auraSystem.hasOwnProperty(tag) && typeof tag === 'string') {
const tagObj = auraSystem[tag];
const info = new TagInfo(null, TagType.SYSTEM, false, []);
const info = new TagInfo(null, 'SYSTEM', false, []);
if (tagObj.attributes) {
for (const a of tagObj.attributes) {
// TODO - could we use more in depth doc from component library here?
Expand All @@ -192,7 +189,7 @@ export default class AuraIndexer implements Indexer {
for (const tag in auraStandard) {
if (auraStandard.hasOwnProperty(tag) && typeof tag === 'string') {
const tagObj = auraStandard[tag];
const info = new TagInfo(null, TagType.STANDARD, false, []);
const info = new TagInfo(null, 'STANDARD', false, []);
if (tagObj.attributes) {
tagObj.attributes.sort((a, b) => {
return a.name.localeCompare(b.name);
Expand Down Expand Up @@ -259,7 +256,7 @@ export default class AuraIndexer implements Indexer {
},
};
const name = componentFromFile(file, sfdxProject);
const info = new TagInfo(file, TagType.CUSTOM, false, [], location, documentation, name, 'c');
const info = new TagInfo(file, 'CUSTOM', false, [], location, documentation, name, 'c');
return info;
}
}
11 changes: 5 additions & 6 deletions packages/aura-language-server/src/aura-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { startServer, addFile, delFile, onCompletion, onHover, onDefinition, onT
import AuraIndexer from './aura-indexer/indexer';
import { toResolvedPath } from '@salesforce/lightning-lsp-common/lib/utils';
import { setIndexer, getAuraTagProvider } from './markup/auraTags';
import { WorkspaceType } from '@salesforce/lightning-lsp-common/lib/shared';
import { getAuraBindingTemplateDeclaration, getAuraBindingValue } from './aura-utils';

interface TagParams {
Expand Down Expand Up @@ -90,7 +89,7 @@ export default class Server {

this.context = new AuraWorkspaceContext(this.workspaceRoots);

if (this.context.type === WorkspaceType.CORE_PARTIAL) {
if (this.context.type === 'CORE_PARTIAL') {
await startServer(path.join(this.workspaceRoots[0], '..'), path.join(this.workspaceRoots[0], '..'));
} else {
await startServer(this.workspaceRoots[0], this.workspaceRoots[0]);
Expand Down Expand Up @@ -164,7 +163,7 @@ export default class Server {
const htmlDocument = this.htmlLS.parseHTMLDocument(document);

const list = this.htmlLS.doComplete(document, completionParams.position, htmlDocument, {
isSfdxProject: this.context.type === WorkspaceType.SFDX,
isSfdxProject: this.context.type === 'SFDX',
useAttributeValueQuotes: true,
});
return list;
Expand Down Expand Up @@ -267,7 +266,7 @@ export default class Server {

try {
if (utils.isAuraRootDirectoryCreated(this.context, changes)) {
await this.context.getIndexingProvider('aura').resetIndex();
this.context.getIndexingProvider('aura').resetIndex();
await this.context.getIndexingProvider('aura').configureAndIndex();
// re-index everything on directory deletions as no events are reported for contents of deleted directories
const startTime = process.hrtime();
Expand All @@ -277,11 +276,11 @@ export default class Server {
for (const event of changes) {
if (event.type === FileChangeType.Deleted && utils.isAuraWatchedDirectory(this.context, event.uri)) {
const dir = toResolvedPath(event.uri);
this.auraIndexer.clearTagsforDirectory(dir, this.context.type === WorkspaceType.SFDX);
this.auraIndexer.clearTagsforDirectory(dir, this.context.type === 'SFDX');
} else {
const file = toResolvedPath(event.uri);
if (file.endsWith('.app') || file.endsWith('.cmp') || file.endsWith('.intf') || file.endsWith('.evt') || file.endsWith('.lib')) {
await this.auraIndexer.indexFile(file, this.context.type === WorkspaceType.SFDX);
await this.auraIndexer.indexFile(file, this.context.type === 'SFDX');
}
}
}
Expand Down
52 changes: 26 additions & 26 deletions packages/aura-language-server/src/aura-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ const RESOURCES_DIR = 'resources';
*/
const AURA_EXPRESSION_REGEX = /['"]?\s*{[!#]\s*[!]?[vmc]\.(\w*)(\.?\w*)*\s*}\s*['"]?/;

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

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

// Create a parse function that works with the new API
export function parse(input: string): HTMLDocument {
export const parse = (input: string): HTMLDocument => {
const languageService = getLanguageService();
const mockDocument = TextDocument.create('file:///mock.html', 'html', 0, input);
return languageService.parseHTMLDocument(mockDocument);
}
};

function stripQuotes(str: string | null) {
const stripQuotes = (str: string | null): string | null => {
if (!str) {
return str;
}
Expand All @@ -70,13 +70,13 @@ function stripQuotes(str: string | null) {
return str.substring(1, str.length - 1);
}
return str;
}
};

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

function getTagNameRange(document: TextDocument, offset: number, tokenType: TokenType, startOffset: number): Range | null {
const getTagNameRange = (document: TextDocument, offset: number, tokenType: TokenType, startOffset: number): Range | null => {
const scanner = createScanner(document.getText(), startOffset);
let token = scanner.scan();
while (token !== TokenType.EOS && (scanner.getTokenEnd() < offset || (scanner.getTokenEnd() === offset && token !== tokenType))) {
Expand All @@ -86,9 +86,9 @@ function getTagNameRange(document: TextDocument, offset: number, tokenType: Toke
return { start: document.positionAt(scanner.getTokenOffset()), end: document.positionAt(scanner.getTokenEnd()) };
}
return null;
}
};

function getAttributeRange(document: TextDocument, attributeName: string, startOffset: number, endOffset: number): Range | null {
const getAttributeRange = (document: TextDocument, attributeName: string, startOffset: number, endOffset: number): Range | null => {
const scanner = createScanner(document.getText(), startOffset);
let token = scanner.scan();
while (token !== TokenType.EOS && scanner.getTokenEnd() < endOffset) {
Expand Down Expand Up @@ -119,9 +119,9 @@ function getAttributeRange(document: TextDocument, attributeName: string, startO
}
}
return null;
}
};

function findAuraDeclaration(document: TextDocument, attributeValue: string, htmlDocument: HTMLDocument): Location | null {
const findAuraDeclaration = (document: TextDocument, attributeValue: string, htmlDocument: HTMLDocument): Location | null => {
for (const root of htmlDocument.roots) {
const attributes = root.children.filter((n) => n.tag === 'aura:attribute');
for (const attribute of attributes) {
Expand All @@ -138,13 +138,13 @@ function findAuraDeclaration(document: TextDocument, attributeValue: string, htm
}
}
return null;
}
};

/**
* Looks for property bindings {PROPERTY.something} within attribute values, or body content, and returns a location
* within the same template that corresponds to iterator:PROPERTY or for:item="PROPERTY".
*/
export function getAuraBindingTemplateDeclaration(document: TextDocument, position: Position, htmlDocument: HTMLDocument): Location | null {
export const getAuraBindingTemplateDeclaration = (document: TextDocument, position: Position, htmlDocument: HTMLDocument): Location | null => {
const offset = document.offsetAt(position);
const node = htmlDocument.findNodeAt(offset);
if (!node || !node.tag) {
Expand All @@ -155,7 +155,7 @@ export function getAuraBindingTemplateDeclaration(document: TextDocument, positi
return findAuraDeclaration(document, propertyValue, htmlDocument);
}
return null;
}
};

/**
* Extracts the Aura binding value at the given position in an HTML document.
Expand All @@ -181,7 +181,7 @@ export function getAuraBindingTemplateDeclaration(document: TextDocument, positi
* @param htmlDocument - The parsed HTML document
* @returns The property/method name from the Aura expression, or null if not found
*/
export function getAuraBindingValue(document: TextDocument, position: Position, htmlDocument: HTMLDocument): string | null {
export const getAuraBindingValue = (document: TextDocument, position: Position, htmlDocument: HTMLDocument): string | null => {
const offset = document.offsetAt(position);
const node = htmlDocument.findNodeAt(offset);

Expand All @@ -198,7 +198,7 @@ export function getAuraBindingValue(document: TextDocument, position: Position,

// If not in an attribute, check if we're in the body text content
return extractAuraExpressionFromContent(document, offset, node);
}
};

/**
* Extracts Aura expression from HTML attribute values.
Expand All @@ -219,7 +219,7 @@ export function getAuraBindingValue(document: TextDocument, position: Position,
* @param node - The HTML node to check
* @returns The property name from the Aura expression, or null if not found
*/
function extractAuraExpressionFromAttribute(document: TextDocument, offset: number, node: any): string | null {
const extractAuraExpressionFromAttribute = (document: TextDocument, offset: number, node: any): string | null => {
const attributeRange = getTagNameRange(document, offset, TokenType.AttributeValue, node.start);
if (!attributeRange) {
return null;
Expand All @@ -238,7 +238,7 @@ function extractAuraExpressionFromAttribute(document: TextDocument, offset: numb
// Extract the property name from the Aura expression
const expressionMatch = AURA_EXPRESSION_REGEX.exec(attributeValue.trim());
return expressionMatch?.[1] ?? null;
}
};

/**
* Extracts Aura expression from HTML body text content.
Expand All @@ -259,7 +259,7 @@ function extractAuraExpressionFromAttribute(document: TextDocument, offset: numb
* @param node - The HTML node to check
* @returns The property name from the Aura expression, or null if not found
*/
function extractAuraExpressionFromContent(document: TextDocument, offset: number, node: any): string | null {
const extractAuraExpressionFromContent = (document: TextDocument, offset: number, node: any): string | null => {
const scanner = createScanner(document.getText(), node.start);
let token = scanner.scan();

Expand Down Expand Up @@ -296,7 +296,7 @@ function extractAuraExpressionFromContent(document: TextDocument, offset: number
}

return null;
}
};

/**
* Extracts the property name from an Aura expression based on cursor position.
Expand All @@ -319,7 +319,7 @@ function extractAuraExpressionFromContent(document: TextDocument, offset: number
* @param expressionEnd - The end index of the Aura expression
* @returns The property name, or null if cursor is not in a valid position
*/
function extractPropertyNameFromExpression(content: string, relativeOffset: number, expressionStart: number, expressionEnd: number): string | null {
const extractPropertyNameFromExpression = (content: string, relativeOffset: number, expressionStart: number, expressionEnd: number): string | null => {
const firstDotIndex = content.indexOf('.', expressionStart);

// If no dot found, return null
Expand Down Expand Up @@ -349,4 +349,4 @@ function extractPropertyNameFromExpression(content: string, relativeOffset: numb
}

return null;
}
};
Loading
Loading