This is probably best done by waiting for 'TAB' to be pressed, then capturing the current text content and caret position, and sending it to the server.
The server can look at session (for pwd) and the session's computer (for file tree) to work out what to return.