1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

Merge remote-tracking branch 'upstream/main' into check-workspace-member-compiler-options

This commit is contained in:
Nayeem Rahman 2024-12-10 17:02:02 +00:00
commit de37f41e13
14 changed files with 79 additions and 41 deletions

View file

@ -1387,7 +1387,7 @@ impl CodeActionCollection {
character: import_start.column_index as u32,
};
let new_text = format!(
"{}// @deno-types=\"{}\"\n",
"{}// @ts-types=\"{}\"\n",
if position.character == 0 { "" } else { "\n" },
&types_specifier_text
);
@ -1400,7 +1400,7 @@ impl CodeActionCollection {
};
Some(lsp::CodeAction {
title: format!(
"Add @deno-types directive for \"{}\"",
"Add @ts-types directive for \"{}\"",
&types_specifier_text
),
kind: Some(lsp::CodeActionKind::QUICKFIX),

View file

@ -1355,7 +1355,7 @@ fn diagnose_resolution(
}
// don't bother warning about sloppy import redirects from .js to .d.ts
// because explaining how to fix this via a diagnostic involves using
// @deno-types and that's a bit complicated to explain
// @ts-types and that's a bit complicated to explain
let is_sloppy_import_dts_redirect = doc_specifier.scheme() == "file"
&& doc.media_type().is_declaration()
&& !MediaType::from_specifier(specifier).is_declaration();
@ -1523,7 +1523,7 @@ fn diagnose_dependency(
.iter()
.map(|i| documents::to_lsp_range(&i.specifier_range))
.collect();
// TODO(nayeemrmn): This is a crude way of detecting `@deno-types` which has
// TODO(nayeemrmn): This is a crude way of detecting `@ts-types` which has
// a different specifier and therefore needs a separate call to
// `diagnose_resolution()`. It would be much cleaner if that were modelled as
// a separate dependency: https://github.com/denoland/deno_graph/issues/247.
@ -1540,7 +1540,7 @@ fn diagnose_dependency(
snapshot,
dependency_key,
if dependency.maybe_code.is_none()
// If not @deno-types, diagnose the types if the code errored because
// If not @ts-types, diagnose the types if the code errored because
// it's likely resolving into the node_modules folder, which might be
// erroring correctly due to resolution only being for bundlers. Let this
// fail at runtime if necessary, but don't bother erroring in the editor
@ -1951,7 +1951,7 @@ let c: number = "a";
&[(
"a.ts",
r#"
// @deno-types="bad.d.ts"
// @ts-types="bad.d.ts"
import "bad.js";
import "bad.js";
"#,
@ -2005,11 +2005,11 @@ let c: number = "a";
"range": {
"start": {
"line": 1,
"character": 23
"character": 21
},
"end": {
"line": 1,
"character": 33
"character": 31
}
},
"severity": 1,

View file

@ -3419,7 +3419,7 @@ fn parse_code_actions(
&specifier_rewrite.new_deno_types_specifier
{
text_edit.new_text = format!(
"// @deno-types=\"{}\"\n{}",
"// @ts-types=\"{}\"\n{}",
deno_types_specifier, &text_edit.new_text
);
}
@ -3594,10 +3594,8 @@ impl CompletionEntryDetails {
if let Some(deno_types_specifier) =
&specifier_rewrite.new_deno_types_specifier
{
*new_text = format!(
"// @deno-types=\"{}\"\n{}",
deno_types_specifier, new_text
);
*new_text =
format!("// @ts-types=\"{}\"\n{}", deno_types_specifier, new_text);
}
}
}

View file

@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fs::File;
@ -637,10 +638,9 @@ impl VfsRoot {
}
}
#[derive(Clone)]
struct FileBackedVfsFile {
file: VirtualFile,
pos: Arc<Mutex<u64>>,
pos: RefCell<u64>,
vfs: Arc<FileBackedVfs>,
}
@ -648,7 +648,7 @@ impl FileBackedVfsFile {
fn seek(&self, pos: SeekFrom) -> FsResult<u64> {
match pos {
SeekFrom::Start(pos) => {
*self.pos.lock() = pos;
*self.pos.borrow_mut() = pos;
Ok(pos)
}
SeekFrom::End(offset) => {
@ -659,7 +659,7 @@ impl FileBackedVfsFile {
.into(),
)
} else {
let mut current_pos = self.pos.lock();
let mut current_pos = self.pos.borrow_mut();
*current_pos = if offset >= 0 {
self.file.offset.len - (offset as u64)
} else {
@ -669,7 +669,7 @@ impl FileBackedVfsFile {
}
}
SeekFrom::Current(offset) => {
let mut current_pos = self.pos.lock();
let mut current_pos = self.pos.borrow_mut();
if offset >= 0 {
*current_pos += offset as u64;
} else if -offset as u64 > *current_pos {
@ -684,7 +684,7 @@ impl FileBackedVfsFile {
fn read_to_buf(&self, buf: &mut [u8]) -> FsResult<usize> {
let read_pos = {
let mut pos = self.pos.lock();
let mut pos = self.pos.borrow_mut();
let read_pos = *pos;
// advance the position due to the read
*pos = std::cmp::min(self.file.offset.len, *pos + buf.len() as u64);
@ -698,7 +698,7 @@ impl FileBackedVfsFile {
fn read_to_end(&self) -> FsResult<Cow<'static, [u8]>> {
let read_pos = {
let mut pos = self.pos.lock();
let mut pos = self.pos.borrow_mut();
let read_pos = *pos;
// todo(dsherret): should this always set it to the end of the file?
if *pos < self.file.offset.len {
@ -734,12 +734,9 @@ impl deno_io::fs::File for FileBackedVfsFile {
self: Rc<Self>,
mut buf: BufMutView,
) -> FsResult<(usize, BufMutView)> {
let inner = (*self).clone();
tokio::task::spawn(async move {
let nread = inner.read_to_buf(&mut buf)?;
Ok((nread, buf))
})
.await?
// this is fast, no need to spawn a task
let nread = self.read_to_buf(&mut buf)?;
Ok((nread, buf))
}
fn write_sync(self: Rc<Self>, _buf: &[u8]) -> FsResult<usize> {
@ -763,8 +760,8 @@ impl deno_io::fs::File for FileBackedVfsFile {
self.read_to_end()
}
async fn read_all_async(self: Rc<Self>) -> FsResult<Cow<'static, [u8]>> {
let inner = (*self).clone();
tokio::task::spawn_blocking(move || inner.read_to_end()).await?
// this is fast, no need to spawn a task
self.read_to_end()
}
fn chmod_sync(self: Rc<Self>, _pathmode: u32) -> FsResult<()> {

View file

@ -100,6 +100,24 @@ fn print_outdated_table(packages: &[OutdatedPackage]) {
println!("{package_fill}{current_fill}{update_fill}{latest_fill}",);
}
#[allow(clippy::print_stdout)]
fn print_suggestion(compatible: bool) {
println!();
let (cmd, txt) = if compatible {
("", "compatible")
} else {
(" --latest", "available")
};
println!(
"{}",
color_print::cformat!(
"<p(245)>Run</> <u>deno outdated --update{}</> <p(245)>to update to the latest {} versions,</>\n<p(245)>or</> <u>deno outdated --help</> <p(245)>for more information.</>",
cmd,
txt,
)
);
}
fn print_outdated(
deps: &mut DepManager,
compatible: bool,
@ -148,6 +166,7 @@ fn print_outdated(
if !outdated.is_empty() {
outdated.sort();
print_outdated_table(&outdated);
print_suggestion(compatible);
}
Ok(())

View file

@ -2701,7 +2701,7 @@ fn lsp_hover_dependency() {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @deno-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\nimport * as h from \"./mod🦕.ts\";\n\nconsole.log(a, b, c, d, e, f, g, h);\n"
"text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @ts-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\nimport * as h from \"./mod🦕.ts\";\n\nconsole.log(a, b, c, d, e, f, g, h);\n"
}
}),
);
@ -6269,7 +6269,7 @@ fn lsp_code_actions_deno_types_for_npm() {
res,
json!([
{
"title": "Add @deno-types directive for \"@types/react\"",
"title": "Add @ts-types directive for \"@types/react\"",
"kind": "quickfix",
"edit": {
"changes": {
@ -6279,7 +6279,7 @@ fn lsp_code_actions_deno_types_for_npm() {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 },
},
"newText": "// @deno-types=\"@types/react\"\n",
"newText": "// @ts-types=\"@types/react\"\n",
},
],
},
@ -6322,7 +6322,7 @@ fn lsp_code_actions_deno_types_for_npm() {
res,
json!([
{
"title": "Add @deno-types directive for \"npm:@types/react@^18.3.10\"",
"title": "Add @ts-types directive for \"npm:@types/react@^18.3.10\"",
"kind": "quickfix",
"edit": {
"changes": {
@ -6332,7 +6332,7 @@ fn lsp_code_actions_deno_types_for_npm() {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 },
},
"newText": "// @deno-types=\"npm:@types/react@^18.3.10\"\n",
"newText": "// @ts-types=\"npm:@types/react@^18.3.10\"\n",
},
],
},
@ -8310,7 +8310,7 @@ fn lsp_npm_auto_import_with_deno_types() {
temp_dir.write(
"other.ts",
r#"
// @deno-types="@types/lz-string"
// @ts-types="@types/lz-string"
import "lz-string";
"#,
);
@ -8358,7 +8358,7 @@ fn lsp_npm_auto_import_with_deno_types() {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 },
},
"newText": "// @deno-types=\"@types/lz-string\"\nimport { compressToBase64 } from \"lz-string\";\n",
"newText": "// @ts-types=\"@types/lz-string\"\nimport { compressToBase64 } from \"lz-string\";\n",
},
],
}),
@ -8391,7 +8391,7 @@ fn lsp_npm_auto_import_with_deno_types() {
"start": { "line": 0, "character": 0 },
"end": { "line": 0, "character": 0 },
},
"newText": "// @deno-types=\"@types/react\"\nimport { createRef } from \"react\";\n",
"newText": "// @ts-types=\"@types/react\"\nimport { createRef } from \"react\";\n",
},
],
}),
@ -10226,7 +10226,7 @@ fn lsp_cache_location() {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @deno-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n"
"text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @ts-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n"
}
}));
assert_eq!(diagnostics.all().len(), 6);
@ -10319,7 +10319,7 @@ fn lsp_tls_cert() {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "import * as a from \"https://localhost:5545/xTypeScriptTypes.js\";\n// @deno-types=\"https://localhost:5545/type_definitions/foo.d.ts\"\nimport * as b from \"https://localhost:5545/type_definitions/foo.js\";\nimport * as c from \"https://localhost:5545/subdir/type_reference.js\";\nimport * as d from \"https://localhost:5545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n"
"text": "import * as a from \"https://localhost:5545/xTypeScriptTypes.js\";\n// @ts-types=\"https://localhost:5545/type_definitions/foo.d.ts\"\nimport * as b from \"https://localhost:5545/type_definitions/foo.js\";\nimport * as c from \"https://localhost:5545/subdir/type_reference.js\";\nimport * as d from \"https://localhost:5545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\nimport * as g from \"http://localhost:4545/x/a/mod.ts\";\n\nconsole.log(a, b, c, d, e, f, g);\n"
}
}));
let diagnostics = diagnostics.all();
@ -10784,7 +10784,7 @@ fn lsp_diagnostics_deno_types() {
"uri": "file:///a/file.ts",
"languageId": "typescript",
"version": 1,
"text": "/// <reference types=\"https://example.com/a/b.d.ts\" />\n/// <reference path=\"https://example.com/a/c.ts\"\n\n// @deno-types=https://example.com/a/d.d.ts\nimport * as d from \"https://example.com/a/d.js\";\n\n// @deno-types=\"https://example.com/a/e.d.ts\"\nimport * as e from \"https://example.com/a/e.js\";\n\nconsole.log(d, e);\n"
"text": "/// <reference types=\"https://example.com/a/b.d.ts\" />\n/// <reference path=\"https://example.com/a/c.ts\"\n\n// @ts-types=https://example.com/a/d.d.ts\nimport * as d from \"https://example.com/a/d.js\";\n\n// @ts-types=\"https://example.com/a/e.d.ts\"\nimport * as e from \"https://example.com/a/e.js\";\n\nconsole.log(d, e);\n"
}
}),
);
@ -10797,7 +10797,7 @@ fn lsp_diagnostics_deno_types() {
}
}),
);
assert_eq!(diagnostics.all().len(), 5);
assert_eq!(diagnostics.all().len(), 4);
client.shutdown();
}
@ -15782,7 +15782,7 @@ fn lsp_sloppy_imports() {
"import * as b from './b.js';\n",
// this one's types resolve to a .d.ts file and we don't
// bother warning about it because it's a bit complicated
// to explain to use @deno-types in a diagnostic
// to explain to use @ts-types in a diagnostic
"import * as c from './c.js';\n",
"console.log(a)\n",
"console.log(b);\n",

View file

@ -13,3 +13,6 @@
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │
└────────────────────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update --latest to update to the latest available versions,
or deno outdated --help for more information.

View file

@ -5,3 +5,6 @@
├──────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │
└──────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update to update to the latest compatible versions,
or deno outdated --help for more information.

View file

@ -7,3 +7,6 @@
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │
└────────────────────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update --latest to update to the latest available versions,
or deno outdated --help for more information.

View file

@ -5,3 +5,6 @@
├──────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/bin │ 0.6.0 │ 0.6.0 │ 1.0.0 │
└──────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update --latest to update to the latest available versions,
or deno outdated --help for more information.

View file

@ -13,3 +13,6 @@
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │
└────────────────────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update --latest to update to the latest available versions,
or deno outdated --help for more information.

View file

@ -3,3 +3,6 @@
├────────────────────────┼─────────┼────────┼────────┤
│ jsr:@denotest/subtract │ 0.2.0 │ 0.2.0 │ 1.0.0 │
└────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update --latest to update to the latest available versions,
or deno outdated --help for more information.

View file

@ -7,3 +7,6 @@
├────────────────────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │
└────────────────────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update --latest to update to the latest available versions,
or deno outdated --help for more information.

View file

@ -3,3 +3,6 @@
├──────────────────────────────────┼─────────┼────────┼────────┤
│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │
└──────────────────────────────────┴─────────┴────────┴────────┘
Run deno outdated --update to update to the latest compatible versions,
or deno outdated --help for more information.