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 @@ -49,6 +49,7 @@
"@typescript-eslint/semi": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "error",
"func-style": ["error", "expression"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I like the const = way much better, easier to read imo and find unused stuff..

"import/no-extraneous-dependencies": "error"
}
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@commitlint/cli": "^7",
"@commitlint/config-conventional": "^7",
"@types/jest": "^29.5.14",
"@types/minimatch": "^5.1.2",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
Expand All @@ -28,7 +27,6 @@
"husky": "^4.2.5",
"lerna": "^3.20.2",
"lint-staged": "^10.2.11",
"patch-package": "^6.0.5",
"prettier": "^2.8.8",
"rimraf": "^3.0.1",
"shelljs": "^0.8.5",
Expand Down Expand Up @@ -81,4 +79,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
24 changes: 10 additions & 14 deletions packages/aura-language-server/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
module.exports = {
displayName: 'unit',
transform: {
".ts": "ts-jest"
},
testRegex: 'src/.*(\\.|/)(test|spec)\\.(ts|js)$',
moduleFileExtensions: [
"ts",
"js",
"json"
],
setupFilesAfterEnv: ["jest-extended"],
testEnvironmentOptions: {
url: 'http://localhost/',
}
displayName: 'unit',
transform: {
'.ts': 'ts-jest',
},
testRegex: 'src/.*(\\.|/)(test|spec)\\.(ts|js)$',
moduleFileExtensions: ['ts', 'js', 'json'],
setupFilesAfterEnv: ['jest-extended', '<rootDir>/jest.setup.js'],
testEnvironmentOptions: {
url: 'http://localhost/',
},
};
12 changes: 12 additions & 0 deletions packages/aura-language-server/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Suppress specific console warnings during tests
const originalWarn = console.warn;

console.warn = (...args) => {
// Suppress the eslint-tool warning from any package
// This log clutters the output and is not useful, hence we suppress it
if (args[0] && args[0].includes('core eslint-tool not installed')) {
return;
}
// Allow other warnings to pass through
originalWarn.apply(console, args);
};
9 changes: 3 additions & 6 deletions packages/aura-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@salesforce/aura-language-server",
"version": "4.12.7",
"description": "Language server for Aura components.",
"main": "lib/aura-indexer/indexer.js",
"typings": "lib/shared.d.ts",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
Expand All @@ -30,16 +30,13 @@
"@salesforce/lightning-lsp-common": "4.12.7",
"acorn-loose": "^6.0.0",
"acorn-walk": "^6.0.0",
"change-case": "^3.1.0",
"fs-extra": "^11.3.0",
"line-column": "^1.0.2",
"vscode-html-languageservice": "^5.0.0",
"vscode-languageserver": "^5.2.1",
"vscode-languageserver-types": "3.17.5",
"vscode-uri": "1.0.6"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/glob": "^7.2.0",
"@types/jest": "^29.5.14",
"@types/mock-fs": "^4.13.4",
Expand All @@ -54,4 +51,4 @@
"ts-jest": "^29.2.6",
"typescript": "5.0.4"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WorkspaceContext } from '@salesforce/lightning-lsp-common';
import { AuraWorkspaceContext } from '../../context/aura-context';
import AuraIndexer from '../indexer';
import * as path from 'path';
import mockFs from 'mock-fs';
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('indexer parsing content', () => {
const ws = 'test-workspaces/sfdx-workspace';
const full = path.resolve(ws);

const context = new WorkspaceContext(ws);
const context = new AuraWorkspaceContext(ws);
await context.configureProject();
const auraIndexer = new AuraIndexer(context);
await auraIndexer.configureAndIndex();
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('indexer parsing content', () => {

it('should index a valid aura component', async () => {
const ws = 'test-workspaces/sfdx-workspace';
const context = new WorkspaceContext(ws);
const context = new AuraWorkspaceContext(ws);
await context.configureProject();
const auraIndexer = new AuraIndexer(context);
await auraIndexer.configureAndIndex();
Expand All @@ -88,7 +88,7 @@ describe('indexer parsing content', () => {

xit('should handle indexing an invalid aura component', async () => {
const ws = 'test-workspaces/sfdx-workspace';
const context = new WorkspaceContext(ws);
const context = new AuraWorkspaceContext(ws);
await context.configureProject();
const auraIndexer = new AuraIndexer(context);
await auraIndexer.configureAndIndex();
Expand Down
22 changes: 12 additions & 10 deletions packages/aura-language-server/src/aura-indexer/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { WorkspaceContext, shared, Indexer, TagInfo, utils, AttributeInfo, componentUtil } from '@salesforce/lightning-lsp-common';
import { shared, 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-extra';
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();

private context: WorkspaceContext;
private context: AuraWorkspaceContext;
private indexingTasks: Promise<void>;

private AURA_TAGS: Map<string, TagInfo> = new Map();
private AURA_EVENTS: Map<string, TagInfo> = new Map();
private AURA_NAMESPACES: Set<string> = new Set();

constructor(context: WorkspaceContext) {
constructor(context: AuraWorkspaceContext) {
this.context = context;
this.context.addIndexingProvider({ name: 'aura', indexer: this });
}
Expand Down Expand Up @@ -55,7 +57,7 @@ export default class AuraIndexer implements Indexer {
}

public clearTagsforDirectory(directory: string, sfdxProject: boolean): void {
const name = componentUtil.componentFromDirectory(directory, sfdxProject);
const name = componentFromDirectory(directory, sfdxProject);
this.deleteCustomTag(name);
}

Expand All @@ -64,7 +66,7 @@ export default class AuraIndexer implements Indexer {
this.clearTagsforFile(file, sfdxProject);
return;
}
const markup = await fs.readFile(file, 'utf-8');
const markup = await fs.promises.readFile(file, 'utf-8');
const result = parse(markup);
const tags = [];
for (const root of result.roots) {
Expand Down Expand Up @@ -133,7 +135,7 @@ export default class AuraIndexer implements Indexer {
}

private clearTagsforFile(file: string, sfdxProject: boolean): void {
const name = componentUtil.componentFromFile(file, sfdxProject);
const name = componentFromFile(file, sfdxProject);
this.deleteCustomTag(name);
}

Expand Down Expand Up @@ -163,7 +165,7 @@ export default class AuraIndexer implements Indexer {
}

private async loadSystemTags(): Promise<void> {
const data = await fs.readFile(auraUtils.getAuraSystemResourcePath(), 'utf-8');
const data = await fs.promises.readFile(auraUtils.getAuraSystemResourcePath(), 'utf-8');
const auraSystem = JSON.parse(data);
for (const tag in auraSystem) {
if (auraSystem.hasOwnProperty(tag) && typeof tag === 'string') {
Expand All @@ -185,7 +187,7 @@ export default class AuraIndexer implements Indexer {
}

private async loadStandardComponents(): Promise<void> {
const data = await fs.readFile(auraUtils.getAuraStandardResourcePath(), 'utf-8');
const data = await fs.promises.readFile(auraUtils.getAuraStandardResourcePath(), 'utf-8');
const auraStandard = JSON.parse(data);
for (const tag in auraStandard) {
if (auraStandard.hasOwnProperty(tag) && typeof tag === 'string') {
Expand Down Expand Up @@ -256,7 +258,7 @@ export default class AuraIndexer implements Indexer {
},
},
};
const name = componentUtil.componentFromFile(file, sfdxProject);
const name = componentFromFile(file, sfdxProject);
const info = new TagInfo(file, TagType.CUSTOM, false, [], location, documentation, name, 'c');
return info;
}
Expand Down
7 changes: 4 additions & 3 deletions packages/aura-language-server/src/aura-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
import { getLanguageService, LanguageService, CompletionList } from 'vscode-html-languageservice';

import URI from 'vscode-uri';
import { WorkspaceContext, utils, interceptConsoleLogger, TagInfo } from '@salesforce/lightning-lsp-common';
import { utils, interceptConsoleLogger, TagInfo } from '@salesforce/lightning-lsp-common';
import { AuraWorkspaceContext } from './context/aura-context';
import { startServer, addFile, delFile, onCompletion, onHover, onDefinition, onTypeDefinition, onReferences, onSignatureHelp } from './tern-server/tern-server';
import AuraIndexer from './aura-indexer/indexer';
import { toResolvedPath } from '@salesforce/lightning-lsp-common/lib/utils';
Expand All @@ -42,7 +43,7 @@ const tagsCleared: NotificationType<void, void> = new NotificationType<void, voi
export default class Server {
readonly connection: IConnection = createConnection();
readonly documents: TextDocuments = new TextDocuments();
context: WorkspaceContext;
context: AuraWorkspaceContext;
workspaceFolders: WorkspaceFolder[];
workspaceRoots: string[];
htmlLS: LanguageService;
Expand Down Expand Up @@ -87,7 +88,7 @@ export default class Server {
}
const startTime = process.hrtime();

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

if (this.context.type === WorkspaceType.CORE_PARTIAL) {
await startServer(path.join(this.workspaceRoots[0], '..'), path.join(this.workspaceRoots[0], '..'));
Expand Down
15 changes: 4 additions & 11 deletions packages/aura-language-server/src/aura-utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Range, TextDocument } from 'vscode-languageserver';
import { utils } from '@salesforce/lightning-lsp-common';
import { HTMLDocument, TokenType, getLanguageService } from 'vscode-html-languageservice';
import { join } from 'path';
import { createScanner } from 'vscode-html-languageservice/lib/umd/parser/htmlScanner';
import { Position, Location } from 'vscode-languageserver-types';

const AURA_STANDARD = 'aura-standard.json';
const AURA_SYSTEM = 'transformed-aura-system.json';
const AURA_EXTENSIONS: string[] = ['.cmp', '.app', '.design', '.evt', '.intf', '.auradoc', '.tokens'];

const RESOURCES_DIR = 'resources';

Expand Down Expand Up @@ -46,11 +44,6 @@ const RESOURCES_DIR = 'resources';
*/
const AURA_EXPRESSION_REGEX = /['"]?\s*{[!#]\s*[!]?[vmc]\.(\w*)(\.?\w*)*\s*}\s*['"]?/;

export function isAuraMarkup(textDocument: TextDocument): boolean {
const fileExt = utils.getExtension(textDocument);
return AURA_EXTENSIONS.includes(fileExt);
}

export function getAuraStandardResourcePath(): string {
return join(__dirname, RESOURCES_DIR, AURA_STANDARD);
}
Expand All @@ -66,7 +59,7 @@ export function parse(input: string): HTMLDocument {
return languageService.parseHTMLDocument(mockDocument);
}

export function stripQuotes(str: string | null) {
function stripQuotes(str: string | null) {
if (!str) {
return str;
}
Expand All @@ -79,11 +72,11 @@ export function stripQuotes(str: string | null) {
return str;
}

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

export function getTagNameRange(document: TextDocument, offset: number, tokenType: TokenType, startOffset: number): Range | null {
function 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 @@ -95,7 +88,7 @@ export function getTagNameRange(document: TextDocument, offset: number, tokenTyp
return null;
}

export function getAttributeRange(document: TextDocument, attributeName: string, startOffset: number, endOffset: number): Range | null {
function 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
Loading
Loading