Skip to content

Commit

Permalink
fix: avoid directories ending in .sol (#285)
Browse files Browse the repository at this point in the history
* fix: avoid directories ending in .sol

* test: fix missing `isFile` in test mocks

Co-authored-by: John Kane <john@kanej.me>
  • Loading branch information
antico5 and kanej committed Nov 24, 2022
1 parent 882d6dc commit b60d161
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/src/services/initialization/indexWorkspaceFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions server/src/utils/WorkspaceFileRetriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ export class WorkspaceFileRetriever {
public async readFile(documentUri: string): Promise<string> {
return (await fs.promises.readFile(documentUri)).toString();
}

public async isFile(fsPath: string) {
return (await fs.promises.stat(fsPath)).isFile();
}
}
5 changes: 5 additions & 0 deletions server/test/helpers/setupMockWorkspaceFileRetriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
1 change: 1 addition & 0 deletions server/test/parser/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function runIndexing(
},
readFile: async () => "",
fileExists: async () => false,
isFile: async () => false,
};

await indexWorkspaceFolders(
Expand Down

0 comments on commit b60d161

Please sign in to comment.