Skip to content

Commit

Permalink
fix: results should still show even if file cannot resolve (calls to …
Browse files Browse the repository at this point in the history
…throws) (#76)
  • Loading branch information
michaelangeloio authored Dec 16, 2023
1 parent 0aa2e91 commit f908556
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
29 changes: 16 additions & 13 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,22 @@ const compile = async ({
}

/**
* Build everything in parallel
* Build everything in parallel after wasm
*/

const result = await compileWasm()
if (result.isError) {
errors.push(result)
return errors
if (path.includes('.rs') || init) {
const result = await compileWasm()
if (result.isError) {
errors.push(result)
return errors
}
}

errors.push(...(await Promise.all([compileClient(), compileServer(), typeCheck('server'), typeCheck('client')])))
return errors
}

async function main() {
const isWatch = process.execArgv.find((arg) => arg.includes('watch'))
const isWatch = process.argv.includes('--watch')
if (!isWatch) {
log('not in watch mode, compiling once')
const errors = await compile({
Expand All @@ -187,22 +188,24 @@ async function main() {
return
}

await compile({
init: true,
ready: true,
path: ''
})

const watcher = watch('**/*.{ts,rs}', {
ignored: '(node_modules|target)/**/*'
ignored: ['(node_modules|target)/**/*', 'server/out/**/*', 'client/out/**/*']
})
let ready = false

watcher.on('ready', async () => {
log('ready')
ready = true
await compile({
init: true,
ready,
path: ''
})
})

watcher.on('change', async (path) => {
log('change', path)
await compile({
init: false,
path,
Expand Down
3 changes: 3 additions & 0 deletions crates/does-it-throw/src/fixtures/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"doesItThrow.trace.server": "verbose"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "bun run build.ts",
"watch": "bun run --watch build.ts",
"watch": "bun run build.ts --watch",
"build": "bun run build.ts",
"vscode:release": "vsce publish",
"vscode:package": "vsce package",
Expand Down
34 changes: 15 additions & 19 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { access, constants, readFile } from 'fs/promises'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { InputData, ParseResult, parse_js } from './rust/does_it_throw_wasm'
import path = require('path')
import { inspect } from 'util'

const connection = createConnection(ProposedFeatures.all)

Expand Down Expand Up @@ -114,12 +115,11 @@ connection.onDidChangeConfiguration((change) => {

function getDocumentSettings(resource: string): Thenable<Settings> {
if (!hasConfigurationCapability) {
connection.console.log(`does not have config capability, using global settings: ${JSON.stringify(globalSettings)}`)
connection.console.info(`does not have config capability, using global settings: ${JSON.stringify(globalSettings)}`)
return Promise.resolve(globalSettings)
}
let result = documentSettings.get(resource)
if (!result) {
connection.console.log(`getting settings for ${resource}`)
result = connection.workspace.getConfiguration({
scopeUri: resource,
section: 'doesItThrow'
Expand Down Expand Up @@ -169,7 +169,7 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
let settings = await getDocumentSettings(textDocument.uri)
if (!settings) {
// this should never happen, but just in case
connection.console.log(`No settings found for ${textDocument.uri}, using defaults`)
connection.console.warn(`No settings found for ${textDocument.uri}, using defaults`)
settings = defaultSettings
}
try {
Expand All @@ -188,19 +188,16 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
const analysis = parse_js(opts) as ParseResult

if (analysis.relative_imports.length > 0) {
const resolvedImports = analysis.relative_imports.map((relative_import) => {
return findFirstFileThatExists(textDocument.uri, relative_import)
const filePromises = analysis.relative_imports.map(async (relative_import) => {
try {
const file = await findFirstFileThatExists(textDocument.uri, relative_import)
return await readFile(file, 'utf-8')
} catch (e) {
connection.console.log(`Error reading file ${inspect(e)}`)
return undefined
}
})
const files = await Promise.all(
resolvedImports.map(async (file) => {
try {
return readFile(await file, 'utf-8')
} catch (e) {
connection.console.log(`Error reading file ${e}`)
return undefined
}
})
)
const files = (await Promise.all(filePromises)).filter((file) => !!file)
const analysisArr = files.map((file) => {
if (!file) {
return undefined
Expand Down Expand Up @@ -234,16 +231,15 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
}
}
}

connection.sendDiagnostics({
uri: textDocument.uri,
diagnostics: analysis.diagnostics
})
} catch (e) {
console.log(e)
connection.console.log(`Error parsing file ${textDocument.uri}`)
connection.console.log(`settings are: ${JSON.stringify(settings)}`)
connection.console.log(`Error: ${e instanceof Error ? e.message : JSON.stringify(e)} error`)
connection.console.error(`Error parsing file ${textDocument.uri}`)
connection.console.error(`settings are: ${JSON.stringify(settings)}`)
connection.console.error(`Error: ${e instanceof Error ? e.message : JSON.stringify(e)} error`)
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] })
}
}
Expand Down

0 comments on commit f908556

Please sign in to comment.