nodejs自动完成的Ternjs

时间:2016-08-10 12:17:08

标签: javascript node.js tern

我正在尝试使用nodejs和tern打印自动完成js文件。 Ternjs拥有我见过的最糟糕的文档。

var tern = require("tern")

var ternServer = new tern.Server({})

var requestDetails = {
        "query": {
            "type": "completions",
            "file": "myfile.js",
            "end": {"line":0,"ch":3},
            "types":true,
            "includeKeywords":true,
            "sort":true,
            "guess":true,
            "docs":true,
            "urls":true,
            "origins":true,
            "lineCharPositions":true,
            "caseInsensitive":true
        },
        "files": [
            {
                "type": "full",
                "name": "myfile.js",
                "text": 'req'
            }
        ]
}

ternServer.request(requestDetails, function(error, success){
    console.log(success);
});

如果我使用con它提供的继续和const它不工作。但不是在那之后。在原子插件中,它提供了模块自动完成功能。我错过了什么。

这也是.tern-project文件

{
  "ecmaVersion": 6,
  "libs": [
    "browser",
    "jquery",
    "requirejs",
    "commonjs"
  ],
  "plugins": {
    "complete_strings": {
      "maxLength": 15
    },
    "node": {},
    "lint": {},
    "doc_comment": {
      "fullDocs": true,
      "strong": true
    }
  }
}

2 个答案:

答案 0 :(得分:3)

以这种方式启动服务器时,不会加载自动完成库。简单地在.tern_project文件中定义它们似乎不起作用。

如果使用node_modules / tern / bin / tern启动服务器,您将获得一个端口,然后您可以成功发布请求并以此方式获得完成。

cv2.drawContours(orig, contour,-1, (0, 255, 0),3) #draw the green contour on image "orig"
(center, size, angle) = cv2.fitEllipse(contour) #get best fit Ellipse from contour
cv2.ellipse(grey_scale,(int(round(center[0])),int(round(center[1]))),(int(round(size[0])),int(round(size[1]))),int(round(angle)),0,360,(0,255,0),1) # draw ellipse on image "grey_scale" with the statistics gathered from second line

如果这对你不起作用,你可以像这样手动添加def文件。

curl -H "Content-Type:e": "completions","file": "myfile.js","end": {"line":0,"ch":3},"types":true,"includeKeywords":true,"sort":true,"guess":true,"docs":true,"urls":true,"origins":true,"lineCharPositions":true,"caseInsensitive":true},"files": [{"type": "full","name": "myfile.js","text": "req"}]}' http://localhost:[PORT]

答案 1 :(得分:3)

如果使用node_modules / tern / bin / tern启动服务器,它将显示一个端口,则您可以成功地发布请求并获得结果。

curl -H "Content-Type:e": "completions","file": "myfile.js","end": {"line":0,"ch":3},"types":true,"includeKeywords":true,"sort":true,"guess":true,"docs":true,"urls":true,"origins":true,"lineCharPositions":true,"caseInsensitive":true},"files": [{"type": "full","name": "myfile.js","text": "req"}]}' http://localhost:[PORT]