diff --git a/pxtcompiler/emitter/service.ts b/pxtcompiler/emitter/service.ts index ce53677d8f9f..da31d3056eb2 100644 --- a/pxtcompiler/emitter/service.ts +++ b/pxtcompiler/emitter/service.ts @@ -858,6 +858,8 @@ namespace ts.pxtc.service { host.setFile(fileName, fileContent); } + const tsFilename = filenameWithExtension(fileName, "ts"); + const span: PosSpan = { startPos: wordStartPos, endPos: wordEndPos } const isPython = /\.py$/.test(fileName); @@ -884,7 +886,6 @@ namespace ts.pxtc.service { let lastNl = src.lastIndexOf("\n", position) lastNl = Math.max(0, lastNl) - const cursorLine = src.substring(lastNl, position) if (dotIdx != -1) complPosition = dotIdx @@ -919,7 +920,7 @@ namespace ts.pxtc.service { // update our language host Object.keys(res.outfiles) .forEach(k => { - if (k.endsWith(".ts")) { + if (k === tsFilename) { host.setFile(k, res.outfiles[k]) } }) @@ -927,7 +928,7 @@ namespace ts.pxtc.service { // convert our location from python to typescript if (res.sourceMap) { const pySrc = src - const tsSrc = res.outfiles["main.ts"] + const tsSrc = res.outfiles[tsFilename] const srcMap = pxtc.BuildSourceMapHelpers(res.sourceMap, tsSrc, pySrc) const smallest = srcMap.py.smallestOverlap(span) @@ -940,7 +941,7 @@ namespace ts.pxtc.service { } const prog = service.getProgram() - const tsAst = prog.getSourceFile("main.ts") // TODO: work for non-main files + const tsAst = prog.getSourceFile(tsFilename) const tc = prog.getTypeChecker() let isPropertyAccess = false; @@ -1873,6 +1874,9 @@ namespace ts.pxtc.service { function findInnerMostNodeAtPosition(n: Node, position: number): Node | null { for (let child of n.getChildren()) { + if (child.kind >= ts.SyntaxKind.FirstPunctuation && child.kind <= ts.SyntaxKind.LastPunctuation) + continue; + let s = child.getStart() let e = child.getEnd() if (s <= position && position < e) @@ -1894,4 +1898,9 @@ namespace ts.pxtc.service { return tc.typeToString(t); } + + function filenameWithExtension(filename: string, extension: string) { + if (extension.charAt(0) === ".") extension = extension.substr(1); + return filename.substr(0, filename.lastIndexOf(".") + 1) + extension; + } } diff --git a/tests/language-service/cases/completions_ignore_tokens.ts b/tests/language-service/cases/completions_ignore_tokens.ts new file mode 100644 index 000000000000..ef5a2f8ee528 --- /dev/null +++ b/tests/language-service/cases/completions_ignore_tokens.ts @@ -0,0 +1,3 @@ +(testNamespace). // testNamespace.someFunction + +;["hello"]. // Array.length; Array.push; Array.set \ No newline at end of file diff --git a/tests/language-service/languageservicerunner.ts b/tests/language-service/languageservicerunner.ts index f896a5a70338..a2fe2a6653be 100644 --- a/tests/language-service/languageservicerunner.ts +++ b/tests/language-service/languageservicerunner.ts @@ -40,7 +40,6 @@ describe("language service", () => { for (const testCase of cases) { it("get completions " + testCase.fileName + testCase.position, () => { - console.log(JSON.stringify(testCase)); return runCompletionTestCaseAsync(testCase); }); } @@ -108,8 +107,6 @@ function runCompletionTestCaseAsync(testCase: CompletionTestCase) { testCase.fileText ); - console.log(result.entries.map(e => e.qName).join(", ")) - for (const sym of testCase.expectedSymbols) { chai.assert(result.entries.some(s => (testCase.isPython ? s.pyQName : s.qName) === sym), `Did not receive symbol '${sym}'`); }