HvyIndustries / crane

PHP Intellisense/code-completion for VS Code
https://hvy.io/crane
Other
240 stars 25 forks source link

Using the server without visiual studio? #359

Open MarcWeber opened 7 years ago

MarcWeber commented 7 years ago

The langserver.org protocol gets used by more and more tools. I'm adding support to https://github.com/MarcWeber/editor-cells right now. But I'm running linux, npm install, removing 'exclude node_modules' form tsconfig.json and running tsc -p causes many failures, caused by not having allowJs, adding allowJs (tsc --version -> 2.3.4 causes stack overflow). Is there a version known to work?

ichiriac commented 7 years ago

Hi Marc,

Not sure it will work out of the box, we may implement a sort of bootstrap. In order to be sure you have a clean install try these steps :

git clone https://github.com/HvyIndustries/crane.git
cd crane/server
npm install
npm run compile
cd ../client/server/
node server.js

The process is actually running and stops without any error as it may expect to be hosted from vs-code (forked process or something like that).

I've took a look at sourcegraph/javascript-typescript-langserver, it's actually supporting language server protocol and is usable outside vscode, here the way they bootstrap the server : https://github.com/sourcegraph/javascript-typescript-langserver/blob/master/src/language-server.ts

Actually this is not on our roadmap, but if you can help us it will be highly appreciated

nevadascout commented 7 years ago

At the moment the Crane language server is tightly integrated in to the client plugin, so it's not suitable for use on it's own. If you could help us split them out it would be much appreciated!

MarcWeber commented 7 years ago

@ichiriac Would you mind telling me the tsc version you've been using ?

ichiriac commented 7 years ago

@MarcWeber, here my versions :

tsc -v
Version 2.1.5
node -v
v7.0.0
npm -v
3.10.8
nvm --version
0.33.0
MarcWeber commented 7 years ago

I confirm that compilation works, however there seems to be a problem with the connection. curl 'http://mawercer.de/tmp/inp' | node ... seems to fail fail and no connection.on method gets called. Haven't had time to find out what's the problem.

MarcWeber commented 7 years ago
// adding to server.ts
process.on('message', (a,b,c) =>{
  console.log("process on message");
});

already fails.

process.on('message') is used in node_modules/vscode-jsonrpc/lib/messageReader.js line 250

https://nodejs.org/api/process.html#process_event_message describes the problem:

If the Node.js process is spawned with an IPC channel (see the Child Process and Cluster documentation), the 'message' event is emitted whenever a message sent by a parent process using childprocess.send() is received by the child process.

simple test case:

curl 'https://mawercer.de/tmp/inp' | node server.js --stdio

--stdio appears in node_modules/vscode-languageserver/lib/main.js|497| but doesn't work. Neither is there --help.

You should be able to reproduce by:

curl 'https://mawercer.de/tmp/inp' | node server.js

Now there are multiple things to fix --stdio does not work as expected --socket=/tmp/sock -> file is not created? --pipe -> unsure what is expected --help -> would be nice

But I'm unsure how to fix - maybe there are updated versions, the other typescript solution uses a dedicated language-server npm implementation

What do you suggest ?

ichiriac commented 7 years ago

Hi @MarcWeber,

I've got it here : https://github.com/Microsoft/vscode-languageserver-node/blob/master/server/src/main.ts#L1414

In order to test it, change this line with :

let connection: IConnection = createConnection();
Debug.setConnection(connection);
Debug.info("Starting crane");

And next run this from the server folder :

npm run compile
echo "foo" | node ../client/server/server.js --stdio
MarcWeber commented 7 years ago

message dropped

MarcWeber commented 7 years ago

I got simple completion working now, but I had to patch Files.ts adding returning decoded without prefixing "/", otherwise SuggestionBuilder.prepare failed in the loop to match the filename. So its strange that buildFromFiles requires paths whereas the server-language protocol recommends 'file://' urls AFAIK So I had to add the if branch here:


        switch (process.platform) {
            case 'darwin':
            case 'linux':
                if (decoded[0] == "/")
                    return decoded; // hack if uri is absolute path return it as is
                return "/" + decoded;

            case 'win32':
                decoded = decoded.replace(/\//g, "\\");
                return decoded;
        }

I'm uncertain about which features should be working.

function bar();
bar() -> goto definition -> does not work

class Foo{
static public function z(){
}
}

Foo::z() -> cursor on z -> goto definition -> jumps to Foo, not to z within Foo

Also updating the files contents doesn't seem to be recognized (but maybe I did something wrong). Thus adding a function like bar() above doesn't make it list bar() even though I send document/didChange with {'text': "full contenst"}

MarcWeber commented 7 years ago

Completion seems to work. There is an alternative project written in TypeScript: https://github.com/bmewburn/vscode-intelephense.git

crane and intelephense fail at -> at bdas which should complete adas() for instance. Also goto definition on bdas doesn't return anything. Even if it does not return the correct position listing all functions / keywords of that name might be helpful.

Or do I still miss something and those cases work for you?

So editor-cells can complete with crane now. So you have a Vim backend which is still work in progress.

<?php

class B{
  public function bdas(){
    return new A();
  }
}

class A{
  public function adas(){
  }
}

class Fooo{
  static public function zoor(){
    return new A();
  }
}

$x = new B();

$x->bdas()->
$x->bdas()->
$x->bdas()->
ichiriac commented 7 years ago

sorry @MarcWeber, but I don't have much time this week. I'll be back next week, but you're welcome to continue and post here your progress, it's really interesting.