vscode“智能感知"和“转到定义"对于非 js/ts 文件

vscode quot;Intellisensequot; and quot;Go to definitionquot; for not js/ts files(vscode“智能感知和“转到定义对于非 js/ts 文件)
本文介绍了vscode“智能感知"和“转到定义"对于非 js/ts 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在前端开发中,我们经常不仅在 javasctipt 中导入 javascript/typescript 文件.我们使用两个别名和相对路径导入此类文件.

例子:

从'~/graphql/queries/brands.gql'导入brandQuery;从 '~/components/common/button/index.vue' 导入按钮;从'./list/index.vue'导入组件;

默认情况下,当我们导入此类文件时,VS Code 不支持非 js/ts 扩展 - 没有智能感知".和转到 Definitoon"对于此类文件.

我尝试了这样的扩展:

<块引用>

这可能在使用 ctrl/cmd 时最有用单击以浏览您的代码.

In frontend-development we often import not only javascript/typescript files in javasctipt. 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.

I tried such extensions: Path intellisense and Path autocomplete

VS Code settings to support alias:

  "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.

Do you know some way to have both "Intellisense", "Go To Definition" for all extensions that I need in my project?

解决方案

See 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. We now support navigating through these imports with go to definition:

This is probably most useful when using ctrl/cmd click to navigate through your code.

这篇关于vscode“智能感知"和“转到定义"对于非 js/ts 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)