picturesbyrobots / td-completes-me

A Simple Auto Completion Engine for Touch Designer
130 stars 5 forks source link

Sublime text! #4

Open omarcostahamido opened 4 years ago

omarcostahamido commented 4 years ago

If there's interest we'll consider a Sublime Text addon. omg-yes

omarcostahamido commented 3 years ago

Hi @picturesbyrobots Just saw your new post here. I'm on mac trying this. Managed to install the sublime package... at least it is showing up when I cmd+shift+p and Package Control: List Packages

Screen Shot 2021-02-28 at 8 56 20 PM

Now, the autocompleting is not really working, or maybe I still don't understand how to use it. I create text dat click on edit button and it opens sublime with an empty .py file. I type op('') and leave the cursor in the middle of the ' and then go edit>show completions it simply type op there... nothing more 😞

picturesbyrobots commented 3 years ago

interesting! Thanks for checking out the repo. Just double checking that you also have downloaded the TOX from this repo and have placed it in the root directory of the TD project that you're trying to get completions for. . If that's the case there also might be an issue with how the completions handler works in ST. It's not super well documented TBH. In my testing I was triggering auto completions with CNTRL+Space. but I can check on the edit show completions method when I get back to a desk.

best. -d

omarcostahamido commented 3 years ago

hi @picturesbyrobots Yes, I've confirmed that I dropped the .tox in TD first. (used the version from the releases tab first, and now the "td_completes_me_v0_3_2" from dev branch) I have to trigger using the menu option because (ctrl+space) is the shortcut for keyboard language change. I'll change the shortcut, eventually. For now, just navigating to the menu option should give the same result. Let me know how can I be of help. Again, great project!

Best, OCH

omarcostahamido commented 3 years ago

just compiled the package from the source and opened the console window in ST while trying it:

using gpu buffer for window
Traceback (most recent call last):
  File "./python3.3/json/decoder.py", line 367, in raw_decode
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/TDCompletesMe/TDCompletesMe.py", line 65, in _get_completions
    new_completions = [[item['label'], item['detail']] for item in json.loads(_data_buf.decode('utf-8'))]
  File "./python3.3/json/__init__.py", line 316, in loads
  File "./python3.3/json/decoder.py", line 351, in decode
  File "./python3.3/json/decoder.py", line 369, in raw_decode
ValueError: No JSON object could be decoded

Note, this may be line 64 for you, because I just added a print() line at start just to make sure the plugin was being loaded when I launched ST.

picturesbyrobots commented 3 years ago

hmm...that error would occur if somehow the buffer coming back to ST is malformed. Which means it's probably something in on the touch side. Would you be able to attach the .TOE you're using to test this or via some sort of file share service? I'm curious to see if I can replicate the behavior over here on my PC.

omarcostahamido commented 3 years ago

Sure thing: TD-ST.toe.zip

picturesbyrobots commented 3 years ago

AH! @omarcostahamido

I'm able to reproduce this issue intermittently. The line that appears to be causing this is 52: while(len(_data_buf) < content_length and current_read_attempt < MAX_READ_ATTEMPTS) : what appears to be happening is that current_read_attempt is reaching MAX_READ_ATTEMPTS before the completion buffer is filled with comprehensible JSON. Which results in the decoder error above. Are you able to get any completions at all? For example in my test setup I'm able to get this error and then select generate completions(via the menu) again and they'll successfully appear.

If that isn't the case you can try the following steps.

line 50 or 51 increase the value of MAX_READ_ATTEMPS to 3000. MAX_READ_ATTEMPTS = 3000

Add this following lines after the while loop breaks around line 66. This should help with debugging

                if(current_read_attempt >= MAX_READ_ATTEMPTS) :
                    print("WARNING. READ ATTEMPS FAILED")
                    print(""" len data is : {}""".format(len(_data_buf)))
                    print("""headers are : {}""".format(headers[2])

There's probably a better way to wait for the completions to come through without blocking the main thread but unfortunately I found that if I don't wait for completions then odds are the entire completion context has changed by the time completions are returned.

omarcostahamido commented 3 years ago

:( I'm still not getting there

made the changes:

using gpu buffer for window
Traceback (most recent call last):
  File "./python3.3/json/decoder.py", line 367, in raw_decode
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/TDCompletesMe/TDCompletesMe.py", line 70, in _get_completions
    new_completions = [[item['label'], item['detail']] for item in json.loads(_data_buf.decode('utf-8'))]
  File "./python3.3/json/__init__.py", line 316, in loads
  File "./python3.3/json/decoder.py", line 351, in decode
  File "./python3.3/json/decoder.py", line 369, in raw_decode
ValueError: No JSON object could be decoded

if I ask it to print those lines regardless (i.e. outside of the if) I get:

headers are : Content-Length: 1140
 len data is : 198

repeated a bunch of time, as you can guess (at least 1494 times)... I just decided to try to print it just in case.

(btw, changes seem to take effect just by editing the py file, no need to compile and restart ST everytime)

picturesbyrobots commented 3 years ago

Hmmm...yeah for some reason the data is being sent through the tcp socket but not read to the buffer. If completions are not being consistently sent to you( i.e. clicking show completions multiple times results in the same thing) I'm going to assume that it's something to do with how the socket programming works on a mac. I'll dig up a mac and see if I can replicate it on that platform.

Out of curiosity if you right click on the textDAT in the attached network and click run do you get anything that prints to the text port?

editing_file_print_test.zip

-d

omarcostahamido commented 3 years ago

Hi @picturesbyrobots

Out of curiosity if you right click on the textDAT in the attached network and click run do you get anything that prints to the text port?

Hum, yeah... it prints None in the textport.

Screen Shot 2021-03-02 at 10 05 12 AM

edit: sorry that was dumb. If I first click edit to open the text DAT in sublime and then run the text DAT I get:

Screen Shot 2021-03-02 at 10 15 32 AM