Skip to content

Commit

Permalink
test: only send host message during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmiller888 committed Apr 8, 2020
1 parent 4e92bbe commit ae53d94
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
25 changes: 13 additions & 12 deletions e2e/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,12 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"

markdown-table@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-1.1.3.tgz#9fcb69bcfdb8717bfd0398c6ec2d93036ef8de60"
integrity sha512-1RUZVgQlpJSPWYbFSpmudq5nHY1doEIv89gBtF0s4gW1GF2XorxcA/70M5vq7rLv0a6mhOUccRsqkwhwLCIQ2Q==
markdown-table@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-2.0.0.tgz#194a90ced26d31fe753d8b9434430214c011865b"
integrity sha512-Ezda85ToJUBhM6WGaG6veasyym+Tbs3cMAw/ZhOPqXiYsr0jgocBV3j3nx+4lk47plLlIqjwuTm/ywVI+zjJ/A==
dependencies:
repeat-string "^1.0.0"

[email protected]:
version "1.43.0"
Expand Down Expand Up @@ -637,6 +639,11 @@ redeyed@~2.1.0:
dependencies:
esprima "~4.0.0"

repeat-string@^1.0.0:
version "1.6.1"
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
integrity sha1-jcrkcOHIirwtYA//Sndihtp15jc=

request@^2.88.0:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
Expand Down Expand Up @@ -700,11 +707,6 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

smart-truncate@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/smart-truncate/-/smart-truncate-1.0.1.tgz#a2173d7abc724a5a30e1b63af88616228b14a475"
integrity sha512-f+kSLMDWKSCpYhwOZM+Da4d8klk5nY4gH57HOEOaaotsZEsTIm/51/9vKDNE26WjU72eBM1zEYdQl6uDwvZfLg==

source-map-support@^0.5.0:
version "0.5.16"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042"
Expand Down Expand Up @@ -814,16 +816,15 @@ ts-mysql-parser@^0.2.0:
typescript "^3.8.3"

"ts-mysql-plugin@file:./..":
version "0.1.7"
version "1.0.0"
dependencies:
antlr4-c3 "^1.1.12"
antlr4ts "^0.5.0-alpha.3"
antlr4ts-cli "^0.5.0-alpha.3"
cross-spawn "^7.0.1"
leven "^3.1.0"
markdown-table "^1.1.3"
markdown-table "^2.0.0"
mysql2 "^2.1.0"
smart-truncate "^1.0.1"
ts-mysql-analyzer "^0.3.0"
ts-mysql-autocomplete "^0.0.2"
ts-mysql-parser "^0.1.2"
Expand Down
20 changes: 7 additions & 13 deletions src/language-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Configuration } from './configuration'
import Logger from './logger'
import { generateDocumentation } from './lib/documentation/generate'
import { createMarkdownTable } from './lib/create-markdown-table'
import { sendHostMessage } from './lib/send-host-message'
import { mapSeverity } from './lib/map-severity'
import { getKind } from './lib/get-kind'

Expand Down Expand Up @@ -70,21 +71,14 @@ export default class MySqlLanguageService implements TemplateLanguageService {
})
}

// For testing purposes, tell client the schema has loaded
private onSchemaLoaded(): void {
const message = {
type: 'event',
event: 'schemaLoadingFinish'
if (process.env.NODE_ENV !== 'test') {
return
}
this.sendResponse(message)
}

// For testing purposes, send response to client
private sendResponse(message: { type: string; event: string }): void {
const json = JSON.stringify(message)
const len = Buffer.byteLength(json, 'utf8')
const formattedMessage = `Content-Length: ${1 + len}\r\n\r\n${json}${this.host.newLine}`
this.host.write(formattedMessage)
sendHostMessage(this.host, {
event: 'schemaLoadingFinish',
type: 'event'
})
}

private createQuickInfo(start: number, text: string, docs: string): QuickInfo {
Expand Down
13 changes: 13 additions & 0 deletions src/lib/send-host-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { server } from 'typescript/lib/tsserverlibrary'

interface HostMessage {
event: string
type: string
}

export function sendHostMessage(host: server.ServerHost, message: HostMessage): void {
const json = JSON.stringify(message)
const len = Buffer.byteLength(json, 'utf8')
const msg = `Content-Length: ${1 + len}\r\n\r\n${json}${host.newLine}`
host.write(msg)
}

0 comments on commit ae53d94

Please sign in to comment.