This repository was archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Support for 'textDocument/hover' #217
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/interface/src/__tests__/__schema__/HoverTestSchema.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
schema { | ||
query: Query | ||
} | ||
|
||
""" This is type documentation for Chicken """ | ||
scalar Chicken | ||
|
||
""" docs for color """ | ||
enum Color { | ||
RED | ||
GREEN | ||
BLUE | ||
} | ||
|
||
union UnionType = String | Float | Boolean | ||
|
||
interface TestInterface { | ||
id: String! | ||
} | ||
|
||
""" This is type documentation for TestType """ | ||
type TestType implements TestInterface { | ||
""" This is field documentation for TestType.testField """ | ||
testField: String | ||
testDeprecatedField: Float @deprecated(reason: "deprecation reason") | ||
testEnumField: Color | ||
} | ||
|
||
type Query { | ||
|
||
""" This is field documentation for Query.thing """ | ||
thing: TestType | ||
listOfThing: [TestType!] | ||
parameterizedField(id: String!): TestType | ||
cluck: Chicken | ||
unionField: UnionType | ||
} |
119 changes: 119 additions & 0 deletions
119
packages/interface/src/__tests__/getHoverInformation-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {Hover} from 'vscode-languageserver-types'; | ||
|
||
import {expect} from 'chai'; | ||
import {beforeEach, describe, it} from 'mocha'; | ||
import fs from 'fs'; | ||
import {buildSchema} from 'graphql'; | ||
import {Position} from 'graphql-language-service-utils'; | ||
import path from 'path'; | ||
|
||
import {getHoverInformation} from '../getHoverInformation'; | ||
|
||
describe('getHoverInformation', () => { | ||
let schema; | ||
beforeEach(async () => { | ||
const schemaIDL = fs.readFileSync( | ||
path.join(__dirname, '__schema__/HoverTestSchema.graphql'), | ||
'utf8', | ||
); | ||
schema = buildSchema(schemaIDL); | ||
}); | ||
|
||
function testHover(query: string, point: Position): Hover.contents { | ||
return getHoverInformation(schema, query, point); | ||
} | ||
|
||
it('provides leaf field information', () => { | ||
const actual = testHover( | ||
'query { thing { testField } }', | ||
new Position(0, 20), | ||
); | ||
expect(actual).to.deep.equal( | ||
'TestType.testField: String\n\n This is field documentation for TestType.testField', | ||
); | ||
}); | ||
|
||
it('provides aliased field information', () => { | ||
const actual = testHover( | ||
'query { thing { other: testField } }', | ||
new Position(0, 25), | ||
); | ||
expect(actual).to.deep.equal( | ||
'TestType.testField: String\n\n This is field documentation for TestType.testField', | ||
); | ||
}); | ||
|
||
it('provides intermediate field information', () => { | ||
const actual = testHover( | ||
'query { thing { testField } }', | ||
new Position(0, 10), | ||
); | ||
expect(actual).to.deep.equal( | ||
'Query.thing: TestType\n\n This is field documentation for Query.thing', | ||
); | ||
}); | ||
|
||
it('provides list field information', () => { | ||
const actual = testHover( | ||
'query { listOfThing { testField } }', | ||
new Position(0, 10), | ||
); | ||
expect(actual).to.deep.equal('Query.listOfThing: [TestType!]'); | ||
}); | ||
|
||
it('provides deprecated field information', () => { | ||
const actual = testHover( | ||
'query { thing { testDeprecatedField } }', | ||
new Position(0, 20), | ||
); | ||
expect(actual).to.deep.equal( | ||
'TestType.testDeprecatedField: Float\n\nDeprecated: deprecation reason', | ||
); | ||
}); | ||
|
||
it('provides enum field information', () => { | ||
const actual = testHover( | ||
'query { thing { testEnumField } }', | ||
new Position(0, 20), | ||
); | ||
expect(actual).to.deep.equal('TestType.testEnumField: Color'); | ||
}); | ||
|
||
it('provides scalar field information', () => { | ||
const actual = testHover('query { cluck }', new Position(0, 10)); | ||
expect(actual).to.deep.equal('Query.cluck: Chicken'); | ||
}); | ||
|
||
it('provides parameter type information', () => { | ||
const actual = testHover( | ||
'query { parameterizedField(id: "foo") { testField } }', | ||
new Position(0, 28), | ||
); | ||
expect(actual).to.deep.equal('Query.parameterizedField(id: String!)'); | ||
}); | ||
|
||
it('provides directive information', () => { | ||
const actual = testHover( | ||
'query { thing { testField @skip(if:true) } }', | ||
new Position(0, 30), | ||
); | ||
expect(actual).to.deep.equal( | ||
'@skip\n\nDirects the executor to skip this field or fragment when the `if` argument is true.', | ||
); | ||
}); | ||
|
||
it('provides union information', () => { | ||
const actual = testHover('query { unionField }', new Position(0, 12)); | ||
expect(actual).to.deep.equal('Query.unionField: UnionType'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as the last PR here - could we defer fetching schema until we're absolutely in need of one?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is about as late as we can leave it – at this point the MessageProcessor has already validated that the hover position contains a graphql document