Skip to content

Commit 85bfc16

Browse files
committed
fix: prfb
1 parent 995d3cf commit 85bfc16

7 files changed

Lines changed: 31 additions & 39 deletions

File tree

packages/salesforcedx-aura-language-server/src/tern-server/ternServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const auraInstanceLastSort = (a: string, b: string): number =>
9191
* Returns an empty array when async find is not available.
9292
*/
9393
const getJsFilesRecursively = async (dirPath: string, fileSystemAccessor: LspFileSystemAccessor): Promise<string[]> =>
94-
(await fileSystemAccessor.findFilesWithGlobAsync('**/*.js', normalizePath(dirPath))) ?? [];
94+
await fileSystemAccessor.findFilesWithGlobAsync('**/*.js', normalizePath(dirPath));
9595

9696
const loadPlugins = async (): Promise<{ aura: true; modules: true; doc_comment: true }> => {
9797
// Use require() to load plugins from file system (they're not bundled)

packages/salesforcedx-lightning-lsp-common/src/providers/lspFileSystemAccessor.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ export class LspFileSystemAccessor {
226226
return stat?.exists ?? false;
227227
}
228228

229-
public async directoryExists(uri: NormalizedPath): Promise<boolean> {
230-
const stat = await this.getFileStat(uri);
231-
return (stat?.exists && stat.type === 'directory') ?? false;
232-
}
233-
234229
public async findFilesWithGlobAsync(pattern: string, basePath: NormalizedPath): Promise<NormalizedPath[]> {
235230
if (!this.connection) return [];
236231
try {

packages/salesforcedx-lightning-lsp-common/src/workspaceReadFileHandler.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,14 @@ export const registerWorkspaceReadFileHandler = (
9797
params: WorkspaceReadDirectoryParams
9898
) {
9999
const { uri } = params;
100-
const vUri = vscode.Uri.parse(uri.toString());
101-
yield* logTo(log, `[readDirectory] request uri=${vUri.toString()}`);
102-
const entries = yield* Effect.tryPromise(() => vscode.workspace.fs.readDirectory(vUri));
100+
yield* logTo(log, `[readDirectory] request uri=${uri.toString()}`);
101+
const entries = yield* Effect.tryPromise(() => vscode.workspace.fs.readDirectory(uri));
103102
const result: DirectoryEntry[] = entries.map(([name, fileType]) => ({
104103
name,
105104
type: vscodeFileTypeToStatType(fileType),
106-
uri: vscode.Uri.joinPath(vUri, name).toString()
105+
uri: vscode.Uri.joinPath(uri, name).toString()
107106
}));
108-
yield* logTo(log, `[readDirectory] success uri=${vUri.toString()} entries=${result.length}`);
107+
yield* logTo(log, `[readDirectory] success uri=${uri.toString()} entries=${result.length}`);
109108
return { entries: result };
110109
});
111110

packages/salesforcedx-lwc-language-server/src/__tests__/lwcServerNode.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ const mockFindFilesConnection = createMockWorkspaceFindFilesConnection(SFDX_WORK
9797
const server: BaseServer = new Server();
9898
server.fileSystemAccessor = sfdxFileSystemAccessor;
9999

100+
const directoryExists = async (fileUri: string): Promise<boolean> => {
101+
const stat = await server.fileSystemAccessor.getFileStat(fileUri);
102+
return (stat?.exists && stat.type === 'directory') ?? false;
103+
};
104+
100105
// Helper function to set up server for tests that need delayed initialization
101106
const setupServerForTest = async (
102107
documentsToOpen: TextDocument[] = [],
@@ -848,7 +853,7 @@ describe('lwcServerNode', () => {
848853
}
849854
}
850855
}
851-
if (await server.fileSystemAccessor.directoryExists(normalizePath(watchedFileDir))) {
856+
if (await directoryExists(watchedFileDir)) {
852857
await deleteFromProvider(server.fileSystemAccessor, watchedFileDir);
853858
}
854859
mockTypeScriptSupportConfig = false;

packages/salesforcedx-lwc-language-server/src/context/lwcContext.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class LWCWorkspaceContext extends BaseWorkspaceContext {
5656
for (const pkg of config.packageDirectories) {
5757
const pkgRoot = normalizePath(path.join(root, pkg.path));
5858

59-
const lwcFiles = (await this.fileSystemAccessor.findFilesWithGlobAsync('**/lwc/**', pkgRoot)) ?? [];
59+
const lwcFiles = await this.fileSystemAccessor.findFilesWithGlobAsync('**/lwc/**', pkgRoot);
6060
const lwcDirs = [
6161
...new Set(
6262
lwcFiles
@@ -70,7 +70,7 @@ export class LWCWorkspaceContext extends BaseWorkspaceContext {
7070
];
7171
roots.lwc.push(...lwcDirs);
7272

73-
const auraFiles = (await this.fileSystemAccessor.findFilesWithGlobAsync('**/aura/**', pkgRoot)) ?? [];
73+
const auraFiles = await this.fileSystemAccessor.findFilesWithGlobAsync('**/aura/**', pkgRoot);
7474
const auraDirs = [
7575
...new Set(
7676
auraFiles
@@ -90,8 +90,10 @@ export class LWCWorkspaceContext extends BaseWorkspaceContext {
9090
case 'CORE_ALL': {
9191
// optimization: discover LWC roots under project/modules/ via findFilesWithGlobAsync
9292
const workspaceRoot = normalizePath(this.workspaceRoots[0]);
93-
const pathsUnderLwc =
94-
(await this.fileSystemAccessor.findFilesWithGlobAsync('*/modules/**/lwc/**', workspaceRoot)) ?? [];
93+
const pathsUnderLwc = await this.fileSystemAccessor.findFilesWithGlobAsync(
94+
'*/modules/**/lwc/**',
95+
workspaceRoot
96+
);
9597
const lwcRootDirs = [
9698
...new Set(
9799
pathsUnderLwc
@@ -108,12 +110,11 @@ export class LWCWorkspaceContext extends BaseWorkspaceContext {
108110
}
109111
case 'CORE_PARTIAL': {
110112
// optimization: discover LWC roots under modules/ via findFilesWithGlobAsync
111-
const pathsUnderModulesLwc =
112-
(await Promise.all(
113-
this.workspaceRoots.map(ws =>
114-
this.fileSystemAccessor.findFilesWithGlobAsync('modules/**/lwc/**', normalizePath(ws))
115-
)
116-
)) ?? [];
113+
const pathsUnderModulesLwc = await Promise.all(
114+
this.workspaceRoots.map(ws =>
115+
this.fileSystemAccessor.findFilesWithGlobAsync('modules/**/lwc/**', normalizePath(ws))
116+
)
117+
);
117118
const lwcRootDirs = [
118119
...new Set(
119120
pathsUnderModulesLwc
@@ -135,7 +136,7 @@ export class LWCWorkspaceContext extends BaseWorkspaceContext {
135136
case 'UNKNOWN': {
136137
// discover all LWC roots via findFilesWithGlobAsync (same dirs findNamespaceRoots would find)
137138
const workspaceRoot = normalizePath(this.workspaceRoots[0]);
138-
const pathsUnderLwc = (await this.fileSystemAccessor.findFilesWithGlobAsync('**/lwc/**', workspaceRoot)) ?? [];
139+
const pathsUnderLwc = await this.fileSystemAccessor.findFilesWithGlobAsync('**/lwc/**', workspaceRoot);
139140
const IGNORED_DIRS = new Set(['node_modules', 'bin', 'target', 'jest-modules', 'repository', 'git']);
140141
const lwcRootDirs = [
141142
...new Set(

packages/salesforcedx-lwc-language-server/src/tag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const findFilesInDirectory = async (
192192
const normalizedDirPath = normalizePath(dirPath);
193193

194194
const globPattern = `${escapeGlob(baseName)}.{html,css}`;
195-
return (await fileSystemAccessor.findFilesWithGlobAsync(globPattern, normalizedDirPath)) ?? [];
195+
return await fileSystemAccessor.findFilesWithGlobAsync(globPattern, normalizedDirPath);
196196
};
197197

198198
// Utility function to get all locations

packages/salesforcedx-lwc-language-server/src/typingIndexer.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,27 @@ const saveCustomLabelTypings = async (indexer: TypingIndexerData): Promise<void>
107107

108108
// Utility function to get meta files
109109
const getMetaFiles = async (indexer: TypingIndexerData): Promise<string[]> => {
110-
const packageDirsPattern = await getSfdxPackageDirsPattern(
111-
indexer.workspaceRoot,
112-
indexer.fileSystemAccessor
113-
);
114-
const found = await indexer.fileSystemAccessor.findFilesWithGlobAsync(
110+
const packageDirsPattern = await getSfdxPackageDirsPattern(indexer.workspaceRoot, indexer.fileSystemAccessor);
111+
return await indexer.fileSystemAccessor.findFilesWithGlobAsync(
115112
`${packageDirsPattern}/**/{staticresources,contentassets,messageChannels}/*.{resource,asset,messageChannel}-meta.xml`,
116113
indexer.workspaceRoot
117114
);
118-
return found ?? [];
119115
};
120116

121117
// Utility function to get meta typings
122118
// visible for testing
123-
export const getMetaTypings = async (indexer: TypingIndexerData): Promise<string[]> => {
124-
const found = await indexer.fileSystemAccessor.findFilesWithGlobAsync(
125-
'*.{messageChannel,resource,asset}.d.ts',
126-
indexer.typingsBaseDir
127-
);
128-
return (found ?? []).map(p => path.resolve(p));
129-
};
119+
export const getMetaTypings = async (indexer: TypingIndexerData): Promise<string[]> =>
120+
await indexer.fileSystemAccessor
121+
.findFilesWithGlobAsync('*.{messageChannel,resource,asset}.d.ts', indexer.typingsBaseDir)
122+
.then(paths => paths.map(p => path.resolve(p)));
130123

131124
// Utility function to get custom label files
132125
const getCustomLabelFiles = async (indexer: TypingIndexerData): Promise<string[]> => {
133126
const packageDirsPattern = await getSfdxPackageDirsPattern(indexer.workspaceRoot, indexer.fileSystemAccessor);
134-
const found = await indexer.fileSystemAccessor.findFilesWithGlobAsync(
127+
return await indexer.fileSystemAccessor.findFilesWithGlobAsync(
135128
`${packageDirsPattern}/**/labels/CustomLabels.labels-meta.xml`,
136129
indexer.workspaceRoot
137130
);
138-
return found ?? [];
139131
};
140132

141133
// Legacy class for backward compatibility (deprecated)

0 commit comments

Comments
 (0)