简体   繁体   English

非 js/ts 文件的 vscode“智能感知”和“转到定义”

[英]vscode "Intellisense" and "Go to definition" for not js/ts files

In frontend-development we often import not only javascript/typescript files in javasctipt.在前端开发中,我们经常不仅在 javasctipt 中导入 javascript/typescript 文件。 We import such files using both aliases an relative paths.我们使用两个别名和相对路径导入此类文件。

Example:例子:

import brandsQuery from '~/graphql/queries/brands.gql';
import Button from '~/components/common/button/index.vue';
import Component from './list/index.vue';

By default VS Code doesn't support not js/ts extensions when we import such files - there are no "Intellisense" and "Go to Definitoon" for such files.默认情况下,当我们导入此类文件时,VS Code 不支持非 js/ts 扩展 - 此类文件没有“Intellisense”和“Go to Definitoon”。

I tried such extensions: Path intellisense and Path autocomplete我尝试了这样的扩展: 路径智能感知路径自动完成

VS Code settings to support alias:支持别名的 VS Code 设置:

  "path-intellisense.mappings": {
    "~/": "${workspaceFolder}",
  },

or或者

  "path-autocomplete.pathMappings": {
    "~/": "${folder}/",
  }

With these extensions we have autocomplete when we write import string.使用这些扩展,我们在编写导入字符串时可以自动完成。 Also for relative paths "Go To Definition" works.也适用于相对路径“转到定义”。

But "Go To Definition" doesn't work for not js-ts files imported using alias.但是“转到定义”不适用于使用别名导入的非 js-ts 文件。

Do you know some way to have both "Intellisense", "Go To Definition" for all extensions that I need in my project?您是否知道某种方法可以让我在项目中需要的所有扩展同时拥有“Intellisense”、“Go To Definition”?

See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_57.md#go-to-definition-for-non-jsts-files请参阅https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_57.md#go-to-definition-for-non-jsts-files

Many modern JS bundlers and frameworks use import statements to import assets such as images and stylesheets.许多现代 JS 捆绑器和框架使用import语句来导入图像和样式表等资产。 We now support navigating through these imports with go to definition :我们现在支持使用go to definition

转到导入的定义

This is probably most useful when using ctrl / cmd click to navigate through your code.这可能在使用ctrl / cmd单击以浏览您的代码时最有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaScript Intellisense VScode [ts()]出现问题 - Problem with JavaScript Intellisense VScode [ts()] vscode+vetur:从 .js 文件转到定义不起作用 - vscode+vetur: go to definition from .js files doesn't work VsCode 不使用单引号格式化 TS/JS 文件 - VsCode not formatting TS/JS files with single quotes 寻找支持 IntelliSense(.js +.ts 文件)的 js 解析器的开源代码 - looking for open source for js parser that support IntelliSense ( .js + .ts files ) VSCODE 跳转到JS文件定义(不是.d.ts文件) - VSCODE Jump to the JS file definition (not the .d.ts file) 如何使用 vscode JavaScript 的“转到定义”交叉文件? - how to using vscode JavaScript's 'go to definition' cross files? VSCode:从JS url(view url)到Django视图的“转到定义” - VSCode: “Go to definition” from JS url (view url) to the Django view 如何在node.js项目中将.d.ts类型本地用于vscode intellisense? - How to use the .d.ts typings locally for vscode intellisense in a node.js project? VScode Intellisense显示的定义不在JSdoc上 - VScode Intellisense shows definition that's not on JSdoc VSCode 仅在导入某处时通过相应的 Foo.d.ts 为 Foo.js 提供智能感知; 如何在 Foo.js 本身中启用智能感知? - VSCode provides intellisense for Foo.js via a corresponding Foo.d.ts only when it’s imported somewhere; how to enable intellisense in a Foo.js itself?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM