atom-archive / xray

An experimental next-generation Electron-based text editor
MIT License
8.48k stars 235 forks source link

[Memo] Adding a file to a subdirectory works, but reading it fails #149

Closed probablycorey closed 5 years ago

probablycorey commented 5 years ago

Example code showing the as at https://gist.github.com/probablycorey/3a673dd08aea886ec3785161d646e46e.

I can add a file to a subdirectory (and I can verify that it worked by calling tree.entries()) but when I call getText using the new fileId I get this error.

    invalid type: null, expected a string
      at request (webpack:/memo/src/index.ts?:61:15)
      at WorkTree.openTextFile (webpack:/memo/src/index.ts?:178:24)
      at VirtualTree.getContent (lib/VirtualTree.ts:162:36)
as-cii commented 5 years ago

Thanks for the report, @probablycorey. We inspected the linked gist and you are calling tree.getText with a file id as opposed to a buffer id. It would actually be a type error if you were using TypeScript in your example.

The right way of using that API is to first call openTextFile(fileId, baseText) and that will return a buffer id that you can then pass to getText:

const bufferId = tree.openTextFile(fileId, "");
console.log(tree.getText(bufferId));

Closing this, but happy to keep discussing it.

probablycorey commented 5 years ago

Doh, my bad. Thanks @as-cii, I double checked the actual code that is causing problems and realized that it is because I'm sending the path instead of the name to rename. 🤦‍♂️