Skip to content

Commit

Permalink
Merge branch 'develop' into wip/procrat/wrong-nested-breadcrumb-order…
Browse files Browse the repository at this point in the history
…ing-6287

* develop:
  Fix shortcuts table formatting (#6644)
  Automatic type based dropdown does not include singleton in a union type (#6629)
  Make Meta.get_annotation work for constructor (#6633)
  Limit the number of reported warnings (#6577)
  Add COOP+COEP+CORP headers (#6597)
  • Loading branch information
Procrat committed May 11, 2023
2 parents cb93a22 + a6fdfc7 commit c1a5cda
Show file tree
Hide file tree
Showing 63 changed files with 713 additions and 190 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@
finalizers][6335]
- [Warning.get_all returns only unique warnings][6372]
- [Reimplement `enso_project` as a proper builtin][6352]
- [Limit number of reported warnings per value][6577]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand Down Expand Up @@ -860,6 +861,7 @@
[6335]: https://github.com/enso-org/enso/pull/6335
[6372]: https://github.com/enso-org/enso/pull/6372
[6352]: https://github.com/enso-org/enso/pull/6352
[6577]: https://github.com/enso-org/enso/pull/6577

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
4 changes: 2 additions & 2 deletions app/gui/docs/product/shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ broken and require further investigation.
#### Debug

| Shortcut | Action |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------- |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>d</kbd> | Toggle Debug Mode. All actions below are only possible when it is activated. |
| <kbd>ctrl</kbd> + <kbd>alt</kbd> + <kbd>shift</kbd> + <kbd>i</kbd> | Open the developer console. |
| <kbd>ctrl</kbd> + <kbd>alt</kbd> + <kbd>shift</kbd> + <kbd>r</kbd> | Reload the visual interface. |
Expand All @@ -137,4 +137,4 @@ broken and require further investigation.
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>enter</kbd> | Push a hardcoded breadcrumb without navigating. |
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>arrow up</kbd> | Pop a breadcrumb without navigating. |
| <kbd>cmd</kbd> + <kbd>i</kbd> | Reload visualizations. To see the effect in the currently shown visualizations, you need to switch to another and switch back. |
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>b</kbd> | | Toggle read-only mode. |
| <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>b</kbd> | Toggle read-only mode. |
4 changes: 4 additions & 0 deletions app/ide-desktop/lib/client/src/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as mime from 'mime-types'
import * as portfinder from 'portfinder'
import createServer from 'create-servers'

import * as common from 'enso-common'
import * as contentConfig from 'enso-content-config'

import * as paths from '../paths'
Expand Down Expand Up @@ -105,6 +106,9 @@ export class Server {
resource === '/preload.cjs.map'
? `${paths.APP_PATH}${resource}`
: `${this.config.dir}${resource}`
for (const [header, value] of common.COOP_COEP_CORP_HEADERS) {
response.setHeader(header, value)
}
fs.readFile(resourceFile, (err, data) => {
if (err) {
logger.error(`Resource '${resource}' not found.`)
Expand Down
13 changes: 12 additions & 1 deletion app/ide-desktop/lib/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @file This module contains metadata about the product and distribution.
/** @file This module contains metadata about the product and distribution,
* and various other constants that are needed in multiple sibling packages.
*
* Code in this package is used by two or more sibling packages of this package. The code is defined
* here when it is not possible for a sibling package to own that code without introducing a
Expand All @@ -12,3 +13,13 @@ export const DEEP_LINK_SCHEME = 'enso'

/** Name of the product. */
export const PRODUCT_NAME = 'Enso'

/** COOP, COEP, and CORP headers: https://web.dev/coop-coep/
*
* These are required to increase the resolution of `performance.now()` timers,
* making profiling a lot more accurate and consistent. */
export const COOP_COEP_CORP_HEADERS: [header: string, value: string][] = [
['Cross-Origin-Embedder-Policy', 'require-corp'],
['Cross-Origin-Opener-Policy', 'same-origin'],
['Cross-Origin-Resource-Policy', 'same-origin'],
]
6 changes: 5 additions & 1 deletion app/ide-desktop/lib/content/esbuild-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import esbuildPluginYaml from 'esbuild-plugin-yaml'
import * as utils from '../../utils'
import BUILD_INFO from '../../build.json' assert { type: 'json' }

export const THIS_PATH = pathModule.resolve(pathModule.dirname(url.fileURLToPath(import.meta.url)))
// =================
// === Constants ===
// =================

const THIS_PATH = pathModule.resolve(pathModule.dirname(url.fileURLToPath(import.meta.url)))

// =============================
// === Environment variables ===
Expand Down
4 changes: 4 additions & 0 deletions app/ide-desktop/lib/content/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const logger = app.log.logger
const ESBUILD_PATH = '/esbuild'
/** SSE event indicating a build has finished. */
const ESBUILD_EVENT_NAME = 'change'
/** Path to the service worker that resolves all extensionless paths to `/index.html`.
* This service worker is required for client-side routing to work when doing local development. */
const SERVICE_WORKER_PATH = '/serviceWorker.js'
/** One second in milliseconds. */
const SECOND = 1000
/** Time in seconds after which a `fetchTimeout` ends. */
Expand All @@ -33,6 +36,7 @@ if (IS_DEV_MODE) {
new EventSource(ESBUILD_PATH).addEventListener(ESBUILD_EVENT_NAME, () => {
location.reload()
})
void navigator.serviceWorker.register(SERVICE_WORKER_PATH)
}

// =============
Expand Down
32 changes: 32 additions & 0 deletions app/ide-desktop/lib/content/src/serviceWorker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @file A service worker that redirects paths without extensions to `/index.html`.
* This is required for paths like `/login`, which are handled by client-side routing,
* to work when developing locally on `localhost:8080`. */
// Bring globals and interfaces specific to Web Workers into scope.
/// <reference lib="WebWorker" />
import * as common from 'enso-common'

// =====================
// === Fetch handler ===
// =====================

// We `declare` a variable here because Service Workers have a different global scope.
// eslint-disable-next-line no-restricted-syntax
declare const self: ServiceWorkerGlobalScope

self.addEventListener('fetch', event => {
const url = new URL(event.request.url)
if (url.hostname === 'localhost' && url.pathname !== '/esbuild') {
event.respondWith(
fetch(event.request.url).then(response => {
const clonedResponse = new Response(response.body, response)
for (const [header, value] of common.COOP_COEP_CORP_HEADERS) {
clonedResponse.headers.set(header, value)
}
return clonedResponse
})
)
return
} else {
return false
}
})
8 changes: 8 additions & 0 deletions app/ide-desktop/lib/content/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/** @file File watch and compile service. */
import * as path from 'node:path'
import * as url from 'node:url'

import * as esbuild from 'esbuild'
import * as portfinder from 'portfinder'
import chalk from 'chalk'
Expand All @@ -12,6 +15,7 @@ import * as dashboardBundler from '../dashboard/esbuild-config'

const PORT = 8080
const HTTP_STATUS_OK = 200
const THIS_PATH = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)))

// ===============
// === Watcher ===
Expand All @@ -29,6 +33,10 @@ async function watch() {
...bundler.argumentsFromEnv(),
devMode: true,
})
opts.entryPoints.push({
in: path.resolve(THIS_PATH, 'src', 'serviceWorker.ts'),
out: 'serviceWorker',
})
const builder = await esbuild.context(opts)
await builder.watch()
await builder.serve({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ export const COMPUTER_ICON = (
</svg>
)

/** An icon representing a user without a profile picture. */
export const DEFAULT_USER_ICON = (
<svg height={32} width={32} viewBox="2 2 20 20" xmlns="http://www.w3.org/2000/svg">
<path
d="M6 20a10 10 0 0 1 6 -18 10 10 0 0 1 6 18 6 6 0 0 0 -4 -5 4.3 4.3 0 0 0 -2 -8 4.3 4.3 0 0 0 -2 8 6 6 0 0 0 -4 5"
fill="#888888"
/>
</svg>
)

export interface StopIconProps {
className?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,7 @@ function Dashboard(props: DashboardProps) {
key={user.user.organization_id}
permissions={PERMISSION[user.permission]}
>
<img
className="rounded-full h-6"
src="https://faces-img.xcdn.link/image-lorem-face-4742.jpg"
/>
{svg.DEFAULT_USER_ICON}
</PermissionDisplay>
))}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ function TopBar(props: TopBarProps) {
</a>
{/* User profile and menu. */}
<div className="transform">
<img
src="https://faces-img.xcdn.link/image-lorem-face-4742.jpg"
className="rounded-full w-8 h-8 bg-cover cursor-pointer"
<div
onClick={event => {
event.stopPropagation()
setUserMenuVisible(!userMenuVisible)
}}
/>
className="rounded-full w-8 h-8 bg-cover cursor-pointer"
>
{svg.DEFAULT_USER_ICON}
</div>
</div>
</div>
)
Expand Down
27 changes: 17 additions & 10 deletions app/ide-desktop/lib/dashboard/src/serviceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @file A service worker that redirects paths without extensions to `/index.html`.
* This is only used in the cloud frontend. */
* This is required for paths like `/login`, which are handled by client-side routing,
* to work when developing locally on `localhost:8081`. */
// Bring globals and interfaces specific to Web Workers into scope.
/// <reference lib="WebWorker" />
import * as common from 'enso-common'

// =====================
// === Fetch handler ===
Expand All @@ -12,17 +15,21 @@ declare const self: ServiceWorkerGlobalScope

self.addEventListener('fetch', event => {
const url = new URL(event.request.url)
if (
url.hostname === 'localhost' &&
/\/[^.]+$/.test(event.request.url) &&
url.pathname !== '/esbuild'
) {
event.respondWith(fetch('/index.html'))
if (url.hostname === 'localhost' && url.pathname !== '/esbuild') {
const responsePromise = /\/[^.]+$/.test(event.request.url)
? fetch('/index.html')
: fetch(event.request.url)
event.respondWith(
responsePromise.then(response => {
const clonedResponse = new Response(response.body, response)
for (const [header, value] of common.COOP_COEP_CORP_HEADERS) {
clonedResponse.headers.set(header, value)
}
return clonedResponse
})
)
return
} else {
return false
}
})

// Required for TypeScript to consider it a module, instead of in window scope.
export {}
5 changes: 5 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type Warning
get_all : Any -> Vector Warning
get_all value = Vector.from_polyglot_array (get_all_array value)

## ADVANCED
Returns `True` if the maximal number of reported warnings for a value has been reached, `False` otherwise.
limit_reached : Any -> Boolean
limit_reached value = @Builtin_Method "Warning.limit_reached"

## PRIVATE
ADVANCED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ from Standard.Base import all
process_to_json_text : Any -> Text
process_to_json_text value =
warnings = Warning.get_all value
text = warnings.map w->w.value.to_display_text
text.to_json
texts = warnings.map w->w.value.to_display_text
vec = case Warning.limit_reached value of
True -> texts + ["Warnings limit reached."]
False -> texts
vec.to_json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ final class ContextEventsListener(
payload: Api.ExpressionUpdate.Payload.Value.Warnings
): ContextRegistryProtocol.ExpressionUpdate.Payload.Value.Warnings =
ContextRegistryProtocol.ExpressionUpdate.Payload.Value
.Warnings(payload.count, payload.warning)
.Warnings(payload.count, payload.warning, payload.reachedMaxCount)

/** Convert the runtime profiling info to the context registry protocol
* representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,13 @@ object ContextRegistryProtocol {
*
* @param count the number of attached warnings
* @param value textual representation of the attached warning
* @param reachedMaxCount indicated whether maximal number of warnings has been reached
*/
case class Warnings(count: Int, value: Option[String])
case class Warnings(
count: Int,
value: Option[String],
reachedMaxCount: Boolean
)
}

case class Pending(message: Option[String], progress: Option[Double])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public class RuntimeOptions {
private static final OptionDescriptor ENABLE_EXECUTION_TIMER_DESCRIPTOR =
OptionDescriptor.newBuilder(ENABLE_EXECUTION_TIMER_KEY, ENABLE_EXECUTION_TIMER).build();

public static final String WARNINGS_LIMIT = optionName("warningsLimit");

@Option(
help = "Maximal number of warnings that can be attached to a value.",
category = OptionCategory.INTERNAL)
public static final OptionKey<Integer> WARNINGS_LIMIT_KEY = new OptionKey<>(100);

private static final OptionDescriptor WARNINGS_LIMIT_DESCRIPTOR =
OptionDescriptor.newBuilder(WARNINGS_LIMIT_KEY, WARNINGS_LIMIT).build();

public static final OptionDescriptors OPTION_DESCRIPTORS =
OptionDescriptors.create(
Arrays.asList(
Expand All @@ -122,7 +132,8 @@ public class RuntimeOptions {
PREINITIALIZE_DESCRIPTOR,
WAIT_FOR_PENDING_SERIALIZATION_JOBS_DESCRIPTOR,
USE_GLOBAL_IR_CACHE_LOCATION_DESCRIPTOR,
ENABLE_EXECUTION_TIMER_DESCRIPTOR));
ENABLE_EXECUTION_TIMER_DESCRIPTOR,
WARNINGS_LIMIT_DESCRIPTOR));

/**
* Canonicalizes the option name by prefixing it with the language name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,13 @@ object Runtime {
*
* @param count the number of attached warnings.
* @param warning textual representation of the attached warning.
* @param reachedMaxCount true when reported a maximal number of allowed warnings, false otherwise.
*/
case class Warnings(count: Int, warning: Option[String])
case class Warnings(
count: Int,
warning: Option[String],
reachedMaxCount: Boolean
)
}

/** TBD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ContextFactory {
* location
* @param options additional options for the Context
* @param executionEnvironment optional name of the execution environment to use during execution
* @param warningsLimit maximal number of warnings reported to the user
* @return configured Context instance
*/
def create(
Expand All @@ -42,6 +43,7 @@ class ContextFactory {
useGlobalIrCacheLocation: Boolean = true,
enableAutoParallelism: Boolean = false,
executionEnvironment: Option[String] = None,
warningsLimit: Int = 100,
options: java.util.Map[String, String] = java.util.Collections.emptyMap
): PolyglotContext = {
executionEnvironment.foreach { name =>
Expand All @@ -67,6 +69,10 @@ class ContextFactory {
RuntimeOptions.ENABLE_AUTO_PARALLELISM,
enableAutoParallelism.toString
)
.option(
RuntimeOptions.WARNINGS_LIMIT,
warningsLimit.toString
)
.option("js.foreign-object-prototype", "true")
.out(out)
.in(in)
Expand Down
Loading

0 comments on commit c1a5cda

Please sign in to comment.