Skip to content

Commit

Permalink
bail when we see the lsp ran already (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Feb 23, 2024
1 parent 06d190d commit f0eb33b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import {
getSource,
} from './ast';
import { resolveTemplate } from './ast/resolve';
import { checkFieldUsageInFile } from './fieldUsage';
import { UNUSED_FIELD_CODE, checkFieldUsageInFile } from './fieldUsage';
import {
MISSING_FRAGMENT_CODE,
getColocatedFragmentNames,
} from './checkImports';
import { NoSubstitutionTemplateLiteral } from 'typescript';

const clientDirectives = new Set([
'populate',
Expand All @@ -49,6 +48,13 @@ const directiveRegex = /Unknown directive "@([^)]+)"/g;
export const SEMANTIC_DIAGNOSTIC_CODE = 52001;
export const MISSING_OPERATION_NAME_CODE = 52002;
export const USING_DEPRECATED_FIELD_CODE = 52004;
export const ALL_DIAGNOSTICS = [
SEMANTIC_DIAGNOSTIC_CODE,
MISSING_OPERATION_NAME_CODE,
USING_DEPRECATED_FIELD_CODE,
MISSING_FRAGMENT_CODE,
UNUSED_FIELD_CODE,
];

const cache = new LRUCache<number, ts.Diagnostic[]>({
// how long to live in ms
Expand Down
7 changes: 6 additions & 1 deletion packages/graphqlsp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ts, init as initTypeScript } from './ts';
import { SchemaOrigin, loadSchema } from './graphql/getSchema';
import { getGraphQLCompletions } from './autoComplete';
import { getGraphQLQuickInfo } from './quickInfo';
import { getGraphQLDiagnostics } from './diagnostics';
import { ALL_DIAGNOSTICS, getGraphQLDiagnostics } from './diagnostics';
import { templates } from './ast/templates';

function createBasicDecorator(info: ts.server.PluginCreateInfo) {
Expand Down Expand Up @@ -62,6 +62,11 @@ function create(info: ts.server.PluginCreateInfo) {
const originalDiagnostics =
info.languageService.getSemanticDiagnostics(filename);

const hasGraphQLDiagnostics = originalDiagnostics.some(x =>
ALL_DIAGNOSTICS.includes(x.code)
);
if (hasGraphQLDiagnostics) return originalDiagnostics;

const graphQLDiagnostics = getGraphQLDiagnostics(filename, schema, info);

return graphQLDiagnostics
Expand Down

0 comments on commit f0eb33b

Please sign in to comment.