Navigation Menu

Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioramos committed Mar 9, 2013
1 parent 87e02d0 commit 6098bfc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
56 changes: 56 additions & 0 deletions example/main.js
@@ -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));
})
5 changes: 5 additions & 0 deletions example/name_of_other_file.js
@@ -0,0 +1,5 @@
var fn = function (a) {return a+10};

fn

var b = ""
3 changes: 3 additions & 0 deletions example/name_of_the_file.js
@@ -0,0 +1,3 @@
console.

var a = []

0 comments on commit 6098bfc

Please sign in to comment.