Permalink
Browse files

add example

  • Loading branch information...
1 parent 87e02d0 commit 6098bfce815c30a6b1885e20131bc77ea7729fee @ramitos ramitos committed Mar 9, 2013
Showing with 64 additions and 0 deletions.
  1. +56 −0 example/main.js
  2. +5 −0 example/name_of_other_file.js
  3. +3 −0 example/name_of_the_file.js
View
@@ -0,0 +1,56 @@
+var fs = require('fs')
+var tern = require('../')
+var acorn = require('acorn')
+var path = require('path')
+
+var environment = [
+ JSON.parse(fs.readFileSync('ecma5.json')),
+ JSON.parse(fs.readFileSync('browser.json'))
+]
+
+var files = {
+ 'name_of_the_file.js': fs.readFileSync(path.join(__dirname, 'name_of_the_file.js'), 'utf8'),
+ 'name_of_other_file.js': fs.readFileSync(path.join(__dirname, 'name_of_other_file.js'), 'utf8')
+}
+
+var getFile = function (name, callback) {
+ callback(null, files[name])
+}
+
+var server = new tern.Server({getFile: getFile}, environment)
+
+server.addFile('name_of_the_file.js')
+server.addFile('name_of_other_file.js')
+
+
+
+server.request({
+ query: {
+ type: 'completions',
+ end: 8,
+ file: 'name_of_the_file.js'
+ },
+ files: [
+ {
+ type: 'full',
+ name: 'name_of_the_file.js',
+ text: files['name_of_the_file.js']
+ }
+ ]
+}, function (e, data) {
+ if(e) throw e
+ console.log(require('util').inspect(data.completions));
+})
+
+
+server.request({
+ query: {
+ type: 'type',
+ end: 39,
+ file: 'name_of_other_file.js'
+ },
+ files: []
+}, function (e, data) {
+ if(e) throw e
+ console.log(require('util').inspect(data));
+})
@@ -0,0 +1,5 @@
+var fn = function (a) {return a+10};
+
+fn
+
+var b = ""
@@ -0,0 +1,3 @@
+console.
+
+var a = []

0 comments on commit 6098bfc

Please sign in to comment.