Skip to content

Commit

Permalink
moar refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 24, 2023
1 parent 2e6d6bd commit 5d3ef64
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/graphqlsp/src/autoComplete.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import ts from 'typescript/lib/tsserverlibrary';
import {
ScriptElementKind,
isIdentifier,
isNoSubstitutionTemplateLiteral,
isTaggedTemplateExpression,
} from 'typescript';
import {
getAutocompleteSuggestions,
getTokenAtPosition,
Expand Down Expand Up @@ -55,7 +49,7 @@ export function getGraphQLCompletions(
isCallExpression &&
node.expression.getText() === tagTemplate &&
node.arguments.length > 0 &&
isNoSubstitutionTemplateLiteral(node.arguments[0])
ts.isNoSubstitutionTemplateLiteral(node.arguments[0])
) {
const foundToken = getToken(node.arguments[0], cursorPosition);
if (!schema.current || !foundToken) return undefined;
Expand All @@ -77,7 +71,7 @@ export function getGraphQLCompletions(
isNewIdentifierLocation: false,
entries: items.map(suggestion => ({
...suggestion,
kind: ScriptElementKind.variableElement,
kind: ts.ScriptElementKind.variableElement,
name: suggestion.label,
kindModifiers: 'declare',
sortText: suggestion.sortText || '0',
Expand All @@ -89,10 +83,10 @@ export function getGraphQLCompletions(
},
})),
};
} else if (isTaggedTemplateExpression(node)) {
} else if (ts.isTaggedTemplateExpression(node)) {
const { template, tag } = node;

if (!isIdentifier(tag) || tag.text !== tagTemplate) return undefined;
if (!ts.isIdentifier(tag) || tag.text !== tagTemplate) return undefined;

const foundToken = getToken(template, cursorPosition);
if (!foundToken || !schema.current) return undefined;
Expand Down Expand Up @@ -128,7 +122,7 @@ export function getGraphQLCompletions(
entries: [
...suggestions.map(suggestion => ({
...suggestion,
kind: ScriptElementKind.variableElement,
kind: ts.ScriptElementKind.variableElement,
name: suggestion.label,
kindModifiers: 'declare',
sortText: suggestion.sortText || '0',
Expand All @@ -141,7 +135,7 @@ export function getGraphQLCompletions(
})),
...spreadSuggestions.map(suggestion => ({
...suggestion,
kind: ScriptElementKind.variableElement,
kind: ts.ScriptElementKind.variableElement,
name: suggestion.label,
insertText: '...' + suggestion.label,
kindModifiers: 'declare',
Expand Down

0 comments on commit 5d3ef64

Please sign in to comment.