diff --git a/server/src/services/initialization/indexWorkspaceFolders.ts b/server/src/services/initialization/indexWorkspaceFolders.ts index 7eadab78..adae9c14 100644 --- a/server/src/services/initialization/indexWorkspaceFolders.ts +++ b/server/src/services/initialization/indexWorkspaceFolders.ts @@ -148,6 +148,10 @@ export async function indexSolidityFiles( const indexedProjects = Object.values(serverState.projects); for (const fileUri of fileUris) { + if (!(await serverState.workspaceFileRetriever.isFile(fileUri))) { + continue; + } + let project: Project = new ProjectlessProject( serverState, path.dirname(fileUri) diff --git a/server/src/utils/WorkspaceFileRetriever.ts b/server/src/utils/WorkspaceFileRetriever.ts index c46507b0..ce7c5e94 100644 --- a/server/src/utils/WorkspaceFileRetriever.ts +++ b/server/src/utils/WorkspaceFileRetriever.ts @@ -32,4 +32,8 @@ export class WorkspaceFileRetriever { public async readFile(documentUri: string): Promise { return (await fs.promises.readFile(documentUri)).toString(); } + + public async isFile(fsPath: string) { + return (await fs.promises.stat(fsPath)).isFile(); + } } diff --git a/server/test/helpers/setupMockWorkspaceFileRetriever.ts b/server/test/helpers/setupMockWorkspaceFileRetriever.ts index 76206337..b1527bdb 100644 --- a/server/test/helpers/setupMockWorkspaceFileRetriever.ts +++ b/server/test/helpers/setupMockWorkspaceFileRetriever.ts @@ -43,9 +43,14 @@ export function setupMockWorkspaceFileRetriever( return false; }; + const isFile = async () => { + return false; + }; + return { findFiles: sinon.spy(findFiles), readFile: sinon.spy(readFile), fileExists: sinon.spy(fileExists), + isFile: sinon.spy(isFile), }; } diff --git a/server/test/parser/analyzer.ts b/server/test/parser/analyzer.ts index eea77c06..533c5195 100644 --- a/server/test/parser/analyzer.ts +++ b/server/test/parser/analyzer.ts @@ -81,6 +81,7 @@ async function runIndexing( }, readFile: async () => "", fileExists: async () => false, + isFile: async () => false, }; await indexWorkspaceFolders(