Skip to content

Commit

Permalink
Change mechanism of reading local files
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Barry Allan <[email protected]>
  • Loading branch information
worksofliam committed Aug 3, 2022
1 parent f8e8764 commit b075489
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/language/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = class {
let type = undefined;

switch (workingUri.scheme) {
case `vscode-vfs`:
case `file`:
// Local file
type = `file`;
Expand Down Expand Up @@ -66,7 +67,7 @@ module.exports = class {
const config = instance.getConfig();
finishedPath = path.posix.join(config.homeDirectory, getPath);
};
break
break;

case `member`:
//Fetch member
Expand Down
7 changes: 4 additions & 3 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ module.exports = class Parser {
}

if (possibleFile) {
content = (await vscode.workspace.fs.readFile(possibleFile)).toString();
uri = possibleFile;
lines = content.replace(new RegExp(`\\\r`, `g`), ``).split(`\n`);
doc = await vscode.workspace.openTextDocument(possibleFile);
eol = doc.eol === vscode.EndOfLine.CRLF ? `\r\n` : `\n`;
uri = doc.uri;
lines = doc.getText().split(eol);
} else {
found = false;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/models/vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = {
Uri,
Position: require(`./Position`),
Range: require(`./Range`),
EndOfLine: {
LF: 1,
CRLF: 2,
},
workspace: {
workspaceFolders: [
{
Expand All @@ -25,6 +29,15 @@ module.exports = {
return fs.readFile(uri.fsPath);
}
},
openTextDocument: async (uri) => {
const content = (await module.exports.workspace.fs.readFile(uri)).toString();

return {
uri,
eol: content.indexOf(`\r\n`) >= 0 ? module.exports.EndOfLine.CRLF : module.exports.EndOfLine.LF,
getText: () => {return content}
}
},
findFiles: async (path) => {
// Sync is fine here since it's just in test
const files = glob.sync(path, {
Expand Down

0 comments on commit b075489

Please sign in to comment.