clausreinke / typescript-tools

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

update get tss confused about linemaps #7

Closed clausreinke closed 10 years ago

clausreinke commented 10 years ago

(copied from #4, reported by @Railk; as it seems to be a different issue)

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

Looks as if the update loses the internal lineMap somewhere, so the source is correct, but tss sees it as a single line, so fails to process commands correctly.

Railk commented 10 years ago

I've looked at all the tss.js code and it seems its needed to refresh the compilerState of the languageService so that the content of the file is updated, i've made the change and don't have the linemap problem anymore.

What i've added :

_this.typescriptLS.updateScript(file, lines.join(EOL));
_this.ls = _this.typescriptLS.getLanguageService().languageService;
_this.ls.refresh();
clausreinke commented 10 years ago

Turned out a bit awkward to find, but in the end, a misuse of API. updateScript kept setting the editRanges to empty, so when the internal compiler state tried to update, it wouldn't find anything to do.

@Railk your addition works because you're creating a new language service instance, with new compiler state, so everything get reparsed, etc.

clausreinke commented 10 years ago

@Railk btw, why not make your Sublime plugin public?-)

Railk commented 10 years ago

@clausreinke Oh ok i see for the languageService. Glad you found the solution to the problem, i tested and it works great now. For the Sublime plugin like it's my first one and the fact i don't do Python often, i was not sure to make it public but if it turns out well, i'll. And like i do a lot of Typescript the goal is to make the plugin work well anyway.