clausreinke / typescript-tools

(repo no longer active) Tools related to the TypeScript language
Apache License 2.0
266 stars 29 forks source link

"update" doesn't work as expected #4

Closed zlumer closed 11 years ago

zlumer commented 11 years ago

Ok, so I got one more problem. I'm trying to get update to work - unfortunately, without success.

Everything works as expected, but then I do update and get an empty completion list. After I reload the project, everything works fine again. The code is unchanged, I just update it with the same lines.

Source code:

///<reference path='../external/typescript/bin/lib.d.ts'/>
var s:string = "";
s.

Log (I've shortened entry lists):

C:\dev\TS>node external\typescript-tools.git\bin\tss.js src\competion.ts
"loaded C:/dev/TS/src/competion.ts, TSS listening.."

> completions true 3 3 C:/dev/TS/src/competion.ts
{"maybeInaccurate":false,"isMemberCompletion":true,"entries":[{"name":"toString","type":"() => string","kind":"method","kindModifiers":"declare,public"},{"name":"charAt","type":"(pos: number) => string","kind":"method","kindModifiers":"declare,public"}, <...> ]}

> reload
"reloaded C:/dev/TS/src/competion.ts, TSS listening.."
> completions true 3 3 C:/dev/TS/src/competion.ts
{"maybeInaccurate":false,"isMemberCompletion":true,"entries":[{"name":"toString","type":"() => string","kind":"method","kindModifiers":"declare,public"},{"name":"charAt","type":"(pos: number) => string","kind":"method","kindModifiers":"declare,public"}, <...> ]}

> update 3 C:/dev/TS/src/competion.ts
///<reference path='../external/typescript/bin/lib.d.ts'/>
var s:string = "";
s.
"updated C:/dev/TS/src/competion.ts"

> completions true 3 3 C:/dev/TS/src/competion.ts
{"maybeInaccurate":false,"isMemberCompletion":true,"entries":[]}

> reload
"reloaded C:/dev/TS/src/competion.ts, TSS listening.."

> completions true 3 3 C:/dev/TS/src/competion.ts
{"maybeInaccurate":false,"isMemberCompletion":true,"entries":[{"name":"toString","type":"() => string","kind":"method","kindModifiers":"declare,public"},{"name":"charAt","type":"(pos: number) => string","kind":"method","kindModifiers":"declare,public"}, <...> ]}
clausreinke commented 11 years ago

That looks like a bug in the handling of line endings. If you

    dump dumpfile C:/dev/TS/src/competion.ts

you'll probably see everything on one line. This was masked because my test-system had double line endings, but I can reproduce the issue by using copy/paste into the commandline.

You could try changing line 272 in typescript-tools/tss.ts to

            this.typescriptLS.updateScript(file,lines.join('\n'));

and rebuild typescript-tools/bin/tss.js. I'll try fixing it cross-system.

zlumer commented 11 years ago

Thanks, that worked. Fun fact: when I trigger update from Windows shell, I get an error. However, when triggered from Process.StandardInput.WriteLine in C#, everything works as expected. It seems that C# sends correct line endings.

Oh, and I also tried the following:

  1. Copy&Paste the whole file to the console.
  2. Press Control+M (CR) at the end of each line instead of Enter. It didn't work.
clausreinke commented 11 years ago

Good to know that this partial fix helps - haven't decided yet how to fix this for good.

Some of the errors are related to a problem in node's readline implementation (joyent/node#3305, just fixed), in combination with windows-style line-endings (\r\n gets turned into two line breaks).

Railk commented 10 years ago

Hello

I'm currently making a small plugin (for me) for SublimeText 3 using TSS testing_v09 branch (really great work !).

For ref i'm using node 0.10.15 on a windows 64bit machine

I've got completions/showErrors/reload command working as it should, but i cannot make the update command work in SublimeText.

So i tried in the windows Shell and i've got the same errors/problems

The content of the file (test2.ts) :

var x = {a:1,b:2};
var y = {c:1,d:2};
x.a;
y.d;

I then update in the shell by copy&paste and by typing line by line to:

var x = {a:1,b:2};
var y = {c:1,d:2};
var z = {e:1,f:2};
x.a;
y.d;

The shell log :

Bash@ /d/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test $ tss test2.ts
"loaded D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts, TSS listening.."

> completions true 4 3 D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts
{"maybeInaccurate":false,"isMemberCompletion":true,"entries":[{"name":"c","kind":"property","kindModifiers":"public","type":"number","fullSymbolName":"c","docComment":""},{"name":"d","kind":"property","kindModifiers":"public","type":"number","fullSymbolName":"d","docComment":""}]}

> update 5 D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts
var x = {a:1,b:2};
var y = {c:1,d:2};
var z = {e:1,f:2};
x.a;
y.d;
"updated D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts"

> completions true 4 3 D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts
"TSS command processing error: Error: error TS5028: Argument out of range: position."

> update 5 D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts
> var x = {a:1,b:2};
var y = {c:1,d:2};
> var z = {e:1,f:2};
x.a;
y.d;
"updated D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts"

> completions true 4 3 D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts
"TSS command processing error: Error: error TS5028: Argument out of range: position."

> dump D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.txt D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts
"dumped D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.ts to D:/X_MEDIAS_X/__DOWNLOAD/SublimeText3/Data/Packages/Typescript_2/test/test2.txt"

I made a dump like you suggested to Zlumer and the result of the dump file is what it should be:

var x = {a:1,b:2};
var y = {c:1,d:2};
var z = {e:1,f:2};
x.a;
y.d;

If i reload everything works fine.

So I'm not sure what i'm making wrong or is it still a problem with readline ?

clausreinke commented 10 years ago

It is not quite the same issue - we're still using a fixed readline (though recent node releases should have the fix anyway). Though the symptons are familiar.

I can reproduce the issue with your example, though strangely not with my test script. Will have to think about what is going on here (the file is as expected, but tss still thinks everything is on a single line, as you can verify by indexing beyond the end of line 1; and that in spite of initial file load and update using the same code path for storing the source..).