Skip to content

Commit

Permalink
Use vscode-uri
Browse files Browse the repository at this point in the history
  • Loading branch information
sockmaster27 committed Jan 27, 2024
1 parent aeadf90 commit f0e4867
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
11 changes: 11 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"portfinder": "^1.0.32",
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.8",
"vscode-uri": "^3.0.8",
"ws": "^8.11.0"
},
"devDependencies": {
Expand Down
7 changes: 2 additions & 5 deletions server/src/engine/flix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import javaVersion from '../util/javaVersion'
import { ChildProcess, spawn } from 'child_process'
import { getPortPromise } from 'portfinder'
import * as _ from 'lodash'
import { URI } from 'vscode-uri'

import * as jobs from './jobs'
import * as queue from './queue'
Expand Down Expand Up @@ -77,11 +78,7 @@ export function getExtensionVersion() {

export function getProjectRootUri() {
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}`)
return URI.file(path)
}

export function updateUserConfiguration(userConfiguration: UserConfiguration) {
Expand Down
25 changes: 18 additions & 7 deletions server/src/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { USER_MESSAGE } from '../util/userMessages'
import { StatusCode } from '../util/statusCodes'

import _ = require('lodash/fp')
import { URI } from 'vscode-uri'

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

function addUriToCompiler(document: TextDocument, skipDelay?: boolean) {
if (!uriIsInProject(document.uri)) {
if (!uriIsInProject(URI.parse(document.uri))) {
sendNotification(jobs.Request.internalMessage, USER_MESSAGE.FILE_NOT_PART_OF_PROJECT())
return
}
Expand All @@ -180,14 +181,24 @@ function addUriToCompiler(document: TextDocument, skipDelay?: boolean) {
queue.enqueue(job, skipDelay)
}

function uriIsInProject(uri: string) {
function uriIsInProject(uri: URI) {
const rootUri = getProjectRootUri()
const regExps = [
String.raw`^${rootUri}/[^/]*\.flix$`,
String.raw`^${rootUri}/src/.*\.flix$`,
String.raw`^${rootUri}/test/.*\.flix$`,

if (rootUri.scheme !== uri.scheme) {
return false
}

if (rootUri.authority !== uri.authority) {
return false
}

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

return pathRegExps.some(pathRegExp => pathRegExp.test(uri.path))
}

/**
Expand Down

0 comments on commit f0e4867

Please sign in to comment.