Skip to content

Commit

Permalink
fix: initial request cache set, import tsc bugs
Browse files Browse the repository at this point in the history
- `handleDidOpenOrSaveNotification` didn't have all param types factored in, leading to retrieving textDocument.text from the wrong place
- by fixing this, the cache is set properly. before, after typescript conversion, initial file cache was not set, only on a valid change would cache set
- fix how imports of node modules happen so that the tsc compiler is happy
- fix prepublish so that it doesnt run the whole shebang on every `yarn` or `yarn add`
  • Loading branch information
acao committed Jan 26, 2020
1 parent bcb2753 commit d3b65a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test": "jest",
"test-mocha": "yarn workspace codemirror-graphql run test",
"test-all": "yarn test && yarn test-mocha",
"ci": "yarn lint && yarn run check && yarn test && yarn build && yarn test-mocha && yarn build-bundles && yarn e2e && yarn build-validate",
"ci": "yarn lint && yarn run check && yarn build && yarn test && yarn test-mocha && yarn build-bundles && yarn e2e && yarn build-validate",
"testonly": "jest && yarn workspace codemirror-graphql run test",
"e2e": "yarn workspace graphiql e2e",
"cypress-open": "yarn workspace graphiql cypress-open",
Expand All @@ -51,7 +51,7 @@
"pretty-check": "node resources/pretty.js --check",
"format": "yarn eslint --fix && yarn pretty",
"lerna-publish": "lerna publish",
"prepublish": "yarn lint && yarn build && yarn build-bundles && yarn test-all && yarn e2e"
"prepublish": "./resources/prepublish.sh"
},
"devDependencies": {
"@babel/cli": "7.7.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-language-service-server/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { Logger as VSCodeLogger } from 'vscode-jsonrpc';

import fs from 'fs';
import os from 'os';
import * as fs from 'fs';
import * as os from 'os';
import { join } from 'path';

const SEVERITY: { [key: string]: string } = {
Expand Down
24 changes: 12 additions & 12 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import { GraphQLLanguageService } from 'graphql-language-service-interface';

import { Range, Position } from 'graphql-language-service-utils';

import { CompletionParams, FileEvent } from 'vscode-languageserver-protocol';
import {
CompletionParams,
FileEvent,
VersionedTextDocumentIdentifier,
DidSaveTextDocumentParams,
DidOpenTextDocumentParams,
} from 'vscode-languageserver-protocol';

import {
Diagnostic,
Expand All @@ -39,8 +45,6 @@ import {
DidChangeWatchedFilesParams,
InitializeParams,
Range as RangeType,
VersionedTextDocumentIdentifier,
DidSaveTextDocumentParams,
TextDocumentPositionParams,
} from 'vscode-languageserver';

Expand Down Expand Up @@ -121,7 +125,7 @@ export class MessageProcessor {
}

async handleDidOpenOrSaveNotification(
params: DidSaveTextDocumentParams,
params: DidSaveTextDocumentParams | DidOpenTextDocumentParams,
): Promise<PublishDiagnosticsParams | null> {
if (!this._isInitialized) {
return null;
Expand All @@ -130,20 +134,18 @@ export class MessageProcessor {
if (!params || !params.textDocument) {
throw new Error('`textDocument` argument is required.');
}

const { text, textDocument } = params;
const { textDocument } = params;
const { uri } = textDocument;

const diagnostics: Diagnostic[] = [];

let contents: CachedContent[] = [];

// Create/modify the cached entry if text is provided.
// Otherwise, try searching the cache to perform diagnostics.
if (text || text === '') {
if ('text' in textDocument && textDocument.text) {
// textDocument/didSave does not pass in the text content.
// Only run the below function if text is passed in.
contents = getQueryAndRange(text, uri);
contents = getQueryAndRange(textDocument.text, uri);
this._invalidateCache(textDocument, uri, contents);
} else {
const cachedDocument = this._getCachedDocument(uri);
Expand Down Expand Up @@ -403,7 +405,7 @@ export class MessageProcessor {

async handleWatchedFilesChangedNotification(
params: DidChangeWatchedFilesParams,
): Promise<PublishDiagnosticsParams[] | null> {
): Promise<Array<PublishDiagnosticsParams | undefined> | null> {
if (!this._isInitialized) {
return null;
}
Expand Down Expand Up @@ -460,9 +462,7 @@ export class MessageProcessor {
change.uri,
false,
);
return { uri: change.uri, diagnostics: [] };
}
return { uri: change.uri, diagnostics: [] };
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/resources/prepublish.sh → resources/prepublish.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ if [ "$CI" != true ]; then
exit 1;
fi;

npm run build;
yarn lint && yarn build && yarn build-bundles && yarn test-all && yarn e2e;

0 comments on commit d3b65a5

Please sign in to comment.