Skip to content

Commit

Permalink
fix: don't include unwanted files on save and change
Browse files Browse the repository at this point in the history
  • Loading branch information
sockmaster27 committed Jan 21, 2024
1 parent 05a6617 commit ea9dab6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 6 additions & 1 deletion server/src/engine/flix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export function getExtensionVersion() {
}

export function getProjectRootUri() {
return _.first(startEngineInput.workspaceFolders)
const path = _.first(startEngineInput.workspaceFolders)!

// This is the format that that VSCode forwards the URI in
const escapedPath = path.replace(':', '%3A')

return new URL(`file:///${escapedPath}`)
}

export function updateUserConfiguration(userConfiguration: UserConfiguration) {
Expand Down
21 changes: 19 additions & 2 deletions server/src/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
InitializeParams,
InitializeResult,
InlayHintParams,
ServerRequestHandler,
TextDocumentChangeEvent,
TextDocumentSyncKind,
} from 'vscode-languageserver'
Expand All @@ -35,7 +34,7 @@ import { getProjectRootUri } from '../engine'
import { USER_MESSAGE } from '../util/userMessages'
import { StatusCode } from '../util/statusCodes'

const _ = require('lodash/fp')
import _ = require('lodash/fp')

interface UriInput {
uri: string
Expand Down Expand Up @@ -168,6 +167,11 @@ export function handleChangeContent(params: TextDocumentChangeEvent<TextDocument
}

function addUriToCompiler(document: TextDocument, skipDelay?: boolean) {
if (!uriIsInProject(document.uri)) {
sendNotification(jobs.Request.internalMessage, USER_MESSAGE.FILE_NOT_PART_OF_PROJECT())
return
}

const job: jobs.Job = {
request: jobs.Request.apiAddUri,
uri: document.uri, // Note: this typically has the file:// scheme (important for files as keys)
Expand All @@ -176,6 +180,16 @@ function addUriToCompiler(document: TextDocument, skipDelay?: boolean) {
queue.enqueue(job, skipDelay)
}

function uriIsInProject(uri: string) {
const rootUri = getProjectRootUri()
const regExps = [
String.raw`^${rootUri}/[^/]*\.flix$`,
String.raw`^${rootUri}/src/.*\.flix$`,
String.raw`^${rootUri}/test/.*\.flix$`,
].map(regExpString => new RegExp(regExpString))
return regExps.some(regExp => regExp.test(uri))
}

/**
* @function
*/
Expand Down Expand Up @@ -382,6 +396,9 @@ function makeVersionResponseHandler(promiseResolver: () => void) {
export function lspCheckResponseHandler({ status, result }: socket.FlixResponse) {
clearDiagnostics()
sendNotification(jobs.Request.internalDiagnostics, { status, result })

// TODO: Find out why TS doen't like this
// @ts-ignore
_.each(sendDiagnostics, result)
}

Expand Down
4 changes: 4 additions & 0 deletions server/src/util/userMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ export class USER_MESSAGE {
static REQUEST_TIMEOUT(retries: number) {
return `Could not send message after ${retries} retries. Websocket not available.`
}

static FILE_NOT_PART_OF_PROJECT() {
return `This file is not included in the project`
}
}

0 comments on commit ea9dab6

Please sign in to comment.